Fundamentals of Data Structures (2)---linked list basic concepts

Source: Internet
Author: User


List of advantages and disadvantages:

Advantages:

No space restrictions

Insert Delete element soon

Disadvantages:

The access speed is very slow.


Defined:

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

Connect to each other by pointers

Each node has only one precursor node, and each node has only one subsequent node

The first node has no precursor 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 is the same as the first node type

There is no valid data stored, the most front is the

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

the operation.

Head pointer: (pointing head)

Pointer variable pointing to head node

Tail Hands:

Pointer to tail node

(The head node may be large, the memory may be large, assuming I want to build a function

Output all linked list values, then if you do not use the head pointer type to do the parameters, that because

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

* * It takes several parameters to determine a list: (or if a function is expected to operate on a linked list.)

Should we at least receive the information from the linked list??? )

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

All information about the linked list.

(the list of programs should be sure to knock it out by themselves)

List categories: single-linked list

Double Linked list:

Each node has two pointer fields

Circular link List

Can find all the other nodes through any node

Single-link list pseudo algorithm: 1. Inserting nodes:

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

P is the address of the node that is pointing, and so is Q. 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 after P

P->next=p->next->next can cause memory leaks, cannot find the node to be deleted, and cannot free up 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);//releases memory occupied by the referred node


Fundamentals of Data Structures (2)---linked list basic concepts

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.