In the second-level C ++ book, the content of the data structure is listed as a chapter, introducing a new concept. These include linear tables, stacks, queues, trees, and Binary Trees.
Data structure: a set of data elements that have one or more specific relationships with each other. Note that the data structure here refers to the logical structure, that is, the relationship, rather than the storage structure. The so-called structure is actually the relationship between the data elements. Therefore, in actual storage, each element must contain information about the relationship with the elements before and after.
According to the complexity of the relationship between various data elements in the data structure, they are divided into linear structure and non-linear structure. There is only one root node in a linear structure, and each node has only one front and one back. Simply put, each node has a maximum of two points. In addition to the linear structure, the data structure is a non-linear structure. As shown in:
To better understand the hierarchical relationships of linear tables, stacks, queues, trees, binary trees, and so on, first take a look and then summarize the linear section.
Linear Data Structure
Linear table concept: a linear table is the simplest and most important structure in the data structure. The position of data elements in a linear table depends only on their own serial numbers, that is, the logical or relative positions are linear. Note that a linear table is stored in an ordered storage structure, that is, the storage space is allocated sequentially according to the logic linear concerns.
Linear table operation: stores data in a sequential storage structure. Therefore, during the insert operation, the elements after the insert position need to be moved back to a space. When deleting an element, you also need to delete all the elements before moving them to a single space.
STACK: A stack is a special linear table of a linear table, so it is also stored in a sequential storage structure. In particular, it is because its operation is limited at one end of the table, while the other end is closed. That is, first, First, Second, first, and foremost.
Stack operation: During the stack operation, the top pointer of the stack is added to 1 and the new element is inserted into the pointer position. If the pointer is currently directed to the last location of the bucket, inbound stack operations cannot be performed, that is, overflow error. Rollback is opposite to inbound operations. if the pointer is 0, overflow is incorrect. This is a little similar to the query in SQL.
Concept of queue: a queue is also a special linear table, which limits the insert operation at one end to the end of the team. The other end is the opposite end. That is, first-in-first-out, and then-out. Note that the queue is stored in a circular structure.
Queue operation: the queuing operation first rear the team's tail pointer, that is, pointing to an empty bucket, and then inserting new elements. When you exit, the first pointer points to the next element of the element to be deleted. Delete the element. At the same time, because it is cyclic storage, when the head pointer and the tail pointer are duplicated, overflow or underflow errors will occur.
Linear Single-chain table: the main difference between a Linear Linked List and a linear table is that each element is divided into two parts instead of stored in a sequential structure, A pointer to a part of related elements. The pointer to a single-linked table only points to the next data.
Linear Linked List Operation: During the insert or delete operation, when a new element is inserted at the insert position, the needles stored by adjacent elements need to change. Other unrelated elements do not need to be changed.
Bilinear linked list: Its Pointer Points to the previous data and the next data.
Two-way linked list operation: the operation is the same as that of one-way linked list, but the pointer to be modified during insertion and deletion is different.
The loop linked list is introduced in the next blog, which is too long. Next article!