Chained storage structure of linear table

First, the definition of chain storage

  • In order to express the logical relationship between each data element and its immediate successor data element, the data element needs to store the information of its immediate successor in addition to its own information.

2. Chained storage logical structure

  • In a linear list based on linked storage, each node contains a data field and a pointer field
  1. Data field: stores the data element itself
  2. Pointer field: store the address of the adjacent node

3. Unification of professional terminology

  • Sequential table: Linear table based on sequential storage structure
  • Linked list: Linear list based on linked storage structure
  1. Singly linked list: each node only contains the address information of the immediate successor
  2. Circular linked list: The immediate successor of the last node in a singly linked list is the first node
  3. Doubly linked list: The nodes in the singly linked list contain the address information of the immediate predecessor and the immediate successor

4. Basic Concepts in Linked Lists

  • Head node: Auxiliary node in the linked list, containing a pointer to the first data element
  • Data node: The node representing the data element in the linked list, in the form of: (data element, address)
  • Tail node: the last data node in the linked list, the address information contained is empty

Five, the node definition of singly linked list


Six, the internal structure of a singly linked list

  • The meaning of the head node in the singly linked list is: the positioning of auxiliary data elements is convenient for insertion and deletion. Therefore, there is no actual data element in the head node.

7. Insert a data element at the target position

  • Start from the head node and locate the target position through the current pointer
  • Apply for a new Node node from the heap space
  • Do the following:
node->value = e;
node->next = current->next;
currnet->next = node;

8. Delete data elements at the target location

  • Start from the head node and locate the target position through the current pointer
  • Use the toDel pointer to point to the node to delete
  • Do the following:
toDel = current->next;
current->next = toDel->next;
delete toDel;

10. Summary

  • The data elements of the linked list have no adjacent relationship in physical memory
  • The nodes in the linked list all contain data fields and pointer fields
  • The head node is used to assist the positioning of data elements , facilitating insertion and deletion operations
  • Insert and delete operations need to ensure the integrity of the linked list


The content of the article comes from the data structure course of Ditai Software College, welcome to exchange!











Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324785390&siteId=291194637