Link list (algorithm analysis and design notes) __ algorithm

Source: Internet
Author: User

The address of the data element in the list is arbitrary.
A set that represents a set of data elements, in which each data element is a node, and the data portion of the node is called the data field of the node. In order to be able to wake up or access the entire list, each node of the linked list should at least contain a location information (often referred to as a pointer field) that points to its immediate successor in physical memory. A node also contains a location information that points to his direct forward element in physical memory. A list of the last node of the pointer field can be empty, the entire linked list of the end.
A linked list of nodes consisting only of a precursor pointer or a successor pointer is called a one-way list, while a linked list with a precursor pointer and a successor pointer is called a two-way list. In practical applications, a head node is usually added to the entire list. This node can be used as an entry point to access the entire list, or as an end tag to traverse the entire list. 1. One-way linked list and its operation

Class Node
{public
   :
      int data
      Node *next;
 } Node
(1) Insert Operation
The procedure for inserting a new node x after position I is to generate the new nodes first, and then to modify the position of the adjacent node pointer fields.
S.next=p.next;
P.next=s;

Picture source See watermark
(2) Delete operation

The process of deleting the first node is to determine where you want to delete the node, and then modify the values in the pointer field for the node.

P.next=s.next;

Picture slightly (' ◡ ') (3) Find Operation

Finds a node in the list that has a value of newelement and returns its position in the list if found, otherwise null.

node * Get (Node *plink,int i) {if (null==plink) return Null;
  int count=0;
  Node * Pnext=plink;
    while (Count<i && pnext!=null) {count++;
  pnext=pnext->next; return Pnext 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.