[Data Structure and Algorithm] Learning Record Collection (02) Linked List

  • This collection is the study record of the "C++ Data Structure and Algorithm" course that the author self-study on the b station. It aims to record the important learning points, thinking content and part of the code, so that it can be read by yourself later, and it can also bring some information to other readers. refer to
  • The content is based on the author’s own understanding or perception, and may contain inappropriate or incorrect contents.
  • System environment: Win10, Visual Studio 2019
  • The picture refers to the online course lecture notes of Northeastern University's "Data Structure and Algorithm Design" (2020)

Table of contents

one-way linked list

circular linked list

Doubly linked list

Two-way circular linked list

cursor list 


The linked list is non-continuous in the memory and uses pointers to record the positional relationship between elements. It can also be subdivided into one-way, two-way, loop, two-way loop, cursor linked list, etc. Each has its own advantages and disadvantages. 

Generally speaking, linked lists are more complex to implement than arrays, and the memory overhead is greater, but their addition and deletion operations are more efficient than arrays (all elements do not need to be moved), and there is no need to consider how much memory space to open when creating ( If the memory space of the array is enlarged for insurance, it may cause a waste of space)

Use #include<list> in C++ to use STL linked list related functions, and program with twice the result with half the effort

one-way linked list

 With a Header node, it occupies space +1, stores the pointer of the first element, and cannot be returned by backword. Because it only stores the address of the subsequent element, the space occupied by a node node is smaller than that of a doubly linked list.

circular linked list

 Compared with a singly linked list, the position of the pointer stored in the last element is not empty, but the pointer of the first element is stored, so it is possible to jump from the tail to the head.

Q How to determine whether the circular list is empty?

The address stored in the pointer field of the head node A is empty if it is first.

Doubly linked list

A node has two pointer fields, which record the pointers of the node's predecessor and successor nodes respectively. It can be traversed forward or backward more conveniently, but a single node takes up more space. Due to the existence of the predecessor and successor, inserting and The deletion operation is relatively more complicated

Two-way circular linked list

It is more flexible and convenient than a simple two-way linked list. The main difference is whether there are head predecessors and tail successor nodes to make the linked list loop.

cursor list 

Because the remaining linked lists frequently use operations (new or delete) for dynamic storage space management, causing complexity in memory management, you can try using a cursor (Cursor) linked list.


The End

Guess you like

Origin blog.csdn.net/Norths_/article/details/125486004