Doubly linked list

Source: Internet
Author: User

1 bidirectional linked list storage structure for linear tables

struct Dulnode {elemtype data;
struct Dulnode *next;
  struct Dulnode *prior;
} Dulnode;
typedef struct DULNODE *dullinklist;

2 since the single-linked list has a circular list, the doubly linked list also has a circular link list

A two-way loop linked list with an empty list of head nodes:

A non-empty linked list with a head node in a two-way circular list:

3 insert operation for doubly linked list, note to modify two pointer variables.

Suppose you want to insert an element s with a data of e between P and P->next.

S->prior = p;s->next = p->next;p->next->prior = s;p->next = s;

The above code must be aware of the order.

4 delete operation of the doubly linked list, note to modify two pointer variables.

P->prior->next = p->next;p->next->prior = p->prior;
Free (p);

Note to release p.

5 because each node of a doubly-linked list needs to record two pointers, it consumes more memory. However, the operation of the junction points is convenient. In other words, space is used to exchange time.

Doubly linked list

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.