Data Structure Fundamentals

Data structure diagram: 1. Linear table    concept: The arrangement of data elements is linear.    Classification: Classification rules are divided according to the storage structure of the elements in the above figure. 1) Sequence table






   Basic idea: The storage space of elements is contiguous. In memory, it is stored sequentially, and the area divided by memory is continuous. The storage structure is as follows:


2) Linked list

   Basic idea: The storage space of elements is discrete, separate (physical), and they can be linked by logical pointers to make it a whole linked list. The storage structure is as follows:


  1. Singly linked list:


   2. Circular linked list:


  3. Doubly linked list (two-way circular linked list):


The difference between the three (from the above three figures we can summarize):
    1. They all have a data field (data(p)) and a pointer field (next(p)), but it can be seen from the figure that the double-linked list has two pointer fields, one to its predecessor and one to its successor.
    2. The pointer field of the last node of the singly linked list is empty, and there is no successor node; the pointer field of the last node of the circular linked list and the double linked list points to the head node, and the next node is the head node, forming a cycle;
    3. Singly linked list and circular linked list It can only be traversed in one direction; doubly linked lists and circular linked lists, where the head node and the tail node are connected together, can be regarded as "headless and tailless"; doubly linked lists can move in two directions, with greater flexibility.



2. Stack

Basic idea: LIFO (last-in, first-out) means that when the elements in the stack are processed, they are processed in the order of LIFO. The stack is also called a LIFO table.

As shown below:


  Example: For a stack of books in a box, only one book can be taken from the top of the book, and the book can only be placed on the top.


3. Queue

  Basic idea: First-in, first-out means that the elements that are received first will be processed first, also known as a first-in, first-out table (FIFO). As shown below:


  举例:排队进车站时,安检行李,先进去的最先出来,后进去的后出来。
分类:
1.顺序队列
顺序队列的操作,要判断队满和队空的标志,从图中我们可以总结得到:
      1.队空:head = tail
      2.队满:tail = m
2.循环队列
循环队列的操作,要判断队空和队满的情况,从图中我们可以总结得到:
    1.队空:head = tail

    2.队满:tail + 1 = head(在队列中会留一个空着的空间,所以要加1)




Guess you like

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