Chain storage structure is characterized by using a set of any storage unit stored data elements. Each element in the linked list can be distributed in various corners of memory, which is not the linked list to be careful, even if each element is in the physical location. It does not improve the productivity of the linked list, so the chain is a data structure that is completely ignored by the physical location and focusing on logical relationships. Such data structures have a large advantage, when inserting or deleting operations, there is no need to move a large number of elements, as long as the pointers of the corresponding elements can be changed, this greatly saves the time spent on the mobile large number of elements, however The disadvantage is also obvious, and he lost the order of sequence tables to access the advantages. The following is some brief description of the linked list. First define a structure: struct person {char name [20]; struct person * name;}; we can see that two items are included in this structure, namely a array defined as a CHAR type and a pointer, this It is the basic composition of the element-node constituting the linked list. From this definition, it is possible to know that a node is composed of both data and pointers, and we refer to the part of the stored data as a data domain, and the corresponding part of the storage pointer is referred to as a pointer domain. The pointer to each node points to the next node, and the last node points to NULL. As for the first node, we define a header node before him, the head node pointer points to the first node, and the data field of the header node does not store anything. When the chain is empty, point the header node directly to NULL. The above is a simple description of the simple description of a linked list, which is one of the operations of the node.
We need to do some preparations, in addition to the need to define a structure that constitutes a list, declare a header pointer is also indispensable. Before using the list, he is a holiday that does not contain any nodes, so it is necessary to initialize the head pointer to NULL, but also need to define a pointer to the chain table structure, which is used to add nodes, of course, may sometimes need multiple such pointer. All the specific implementations are as follows: struct person {char name [20]; struct person * next;}; struct person * new; struct person * head; head = null; When everything is ready, we can make a chain list Operate.
* Add the node to the beginning of the linked list If the head pointer is null, then the linked list is a blank table, the newly added node is the unique node in the list. At this time, what we have to do is to let the head pointer points to the new node, and the pointer to the new node points to NULL. Or before the linked list is not empty, just point the new node's pointer to the original first node when you insert a new node. No matter that, they all have several common features: 1. Use malloc allocation space; 2. Set the pointer of the new node to the value of the head pointer; 3. Let the head pointer points to the new contact. The specific implementation is as follows: New = (Person *) Malloc (Struct Person); new-> next = head; Head = new;
* Add nodes to the end of the chain to add the node to the end of the chain, start from the head pointer, until the last node, traversing the entire linked list. 1. Assign space; 2. The next node's next pointer points to the new node; 3. Set the next NEXT to NULL. Code: Person * current; // Define the current pointer ... current = head; while (current-> next! = Null) current = current-> next; // Traverse the entire Link table Node New = (Person *) Malloc (Sizeof (struct person)); current-> next = new; // new pointer points to the NEXT position of the current pointer new-> next = null; * Fill the node into the middle of the linked list. In most cases, we need to insert when we use the list. The node, the steps are as follows: 1. First determine which node of the linked list is to join. We call it a marker node; 2. Assign space; 3. Point the NEXT pointer of the tag node points to the new element; 4. Point the NEXT pointer of the new node points to the node pointing to the tag node. Code: Person * Marker; ... new = (pers) Malloc (Struct Person) NEW-> Next = Marker-> Next; Marker-> Next = New;
The above is the definition of single-strand table and some basic operations, and some actual work can be done, such as character sorting. There is also a content involving deleting nodes, not discussing today. Basic operations that are familiar with nodes are essential for in-depth linkers, while in-depth learning lins are very helpful for the entry of the data structure. The data structure is a discipline that makes people feel very touched. Even if I don't know what it can do, the general reading is obviously possible to read more dizzy, find a good entry point to go deep, after a period of time It will truly understand the essence of the data structure. I want to learn the procedure, the data structure is a discipline that is not jumped, and the inaction is hard in the future.