Data Structure Foundation (2)---linked list basic concept __ data structure

Source: Internet
Author: User

The advantages and disadvantages of the linked list:

Advantages:

There is no limit to space

Insert deletion element quickly

Disadvantages:

The access speed is slow.

Defined:

N-node discrete allocations (not contiguous storage in memory)

Connect to each other through the pointer

Each node has only one predecessor node, each node has only one successor node

The first node has no predecessor node, and the tail node has no subsequent nodes.

First node:

First valid node

Tail Node:

Last valid node

Head node:

The data type of the header node is the same as the type of the first

No valid data is stored, the most front one is

Before the first node, mainly for the convenience of the linked list

The operation.

Head pointer: (pointing to head)

Pointer variable pointing to the head node

Tail pointer:

Pointer to tail node

(The head node may be large, the memory may be large, suppose I want to create a function

Output the value of all linked lists, if you do not use the head pointer type as a parameter, that

The head nodes of different lists are not the same size, so there is no way to find the parameters.

* * Determine that a list requires several parameters: (or if you expect a function to operate on a linked list)

We need to at least receive the information from the list ... )

Only need one parameter: the head pointer, because through it we can launch

All the information for the linked list.

(The list of procedures better be sure to knock out yourself)

Category of linked list: single linked list

Double Linked list:

Each node has two pointer fields

Circular chain List

Can find all the other nodes through any one node

Single linked list pseudo algorithm: 1. Insert node:

Insert a node that is pointed to by Q after the node to which P points:

P Stores the address of the node to which it points, and Q is. The next pointer holds the address of the next element.

q->next=p->next;p->next=q;

can also

r=p->next; p->next=q;q->next=r;

Delete the node following p

P->next=p->next->next can cause memory leaks, unable to locate the node to be deleted, and unable to free memory.

Correct practice: Temporarily define a pointer r to hold the address of the node to be deleted

r=p->next;

p->next=p->next->next;

Free (R);/release memory occupied by the indicated node


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.