[Data Structure]——Linear Table Short Answer Question Template

1. Sequence table

[What is a sequence table/The difference between an array and a sequence table]

1. What is the difference between an array and a sequence list?

: The sequence table reflects the linear relationship between data elements, that is, the one-to-one relationship, and a set of operations defined on the data elements, so it is easier to implement and convenient to operate than the array, while the array is only in the physical area A set of continuous storage units, which is a form in which several elements of the same type are organized in an unordered manner.

2. Linked list

[The difference between head pointer and head node]

1. Explain the fundamental difference between the head pointer and the head node in the linked storage structure of the linear list, and the relationship between the head node and the first node.

: ① The head pointer has an identification function. The commonly used head pointer refers to the name of the linked list, and can prevent the linked list from being empty; the setting of the head node can make the insertion or deletion operations unified and convenient.
②The first element node is the first element node, that is, the first node after the head node.


Singly linked list with head node

2. What is the function of setting the head node in a singly linked list?

: ① Prevent the singly linked list from being empty. If the singly linked list is empty, it will be an empty linked list, that is, the head node L→next=NULL;
② Ensure the insertion of elements And the unity of deletion element operation, the storage location of a singly linked list with a head node is stored in the pointer field of the head node L, pointing to the first node of the singly linked list.


surface classification

3. What categories can linked lists be divided into through pointers?

: According to the number of pointers contained in each node in the linked storage structure of the linear list, the linear linked list can be divided into a single linked list and a double linked list, and according to the connection method of the pointers, the linked list can be divided into a static linked list and a (dynamic) linked list. .

3. Comparison between sequence list and linked list

[The difference between sequential list and linked list storage]

1. Briefly describe the characteristics of sequence list and linked list storage methods.

: ① The sequence table is simple to implement and can be accessed randomly. Its storage density is high, but inserting and deleting operations require moving a large number of elements, which is inefficient. In addition, its storage space needs to be allocated in advance, which can easily cause space waste or overflow. .
②The linked list does not support random access and can only be accessed sequentially. The logical relationship between elements is reflected through pointers. The storage density is smaller than that of the sequential list. It does not require movement to perform insertion and deletion operations. Elements only need to modify the pointer, which is highly efficient. In addition, it also supports dynamic allocation of storage space without causing space waste or overflow.


[Logical relationship between data elements in different storage structures]

2. How do sequential storage structures and chained storage structures represent the logical relationship between data elements?

: The sequential storage structure expresses logical relationships through physically adjacent addresses, while the chained storage structure expresses logical relationships through pointers.


Selection of linear table storage structure

3. If the linear table inserts and deletes frequently, what storage structure should be used? Why?

: Chained storage structure. This structure does not need to move a large number of elements when performing insertion and deletion operations, but only needs to modify the pointer, and can support dynamic allocation of storage space.

4. Circular linked list

Advantages of circular singly linked list

1. What is the biggest advantage of cyclic singly linked list?

: In a circular singly linked list, every element in the linked list can be accessed from any node.

5. Static linked list

Stillness and expression concept

1. Briefly describe the definition of static linked list and its advantages and disadvantages.

: A static linked list uses an array to describe the linked structure. Each array element has two components. One is the value of the data element, and the other is a pointer. The pointer points to the position (subscript) of the next element in the array. When inserting and deleting a static linked list, you only need to modify the pointer without moving the data, but the static linked list cannot be accessed randomly. In addition, if the defined array is too large, it may waste more storage space.

6. Insertion and deletion code for singly linked list

Introduction to the front page

1. In a singly linked list, insert node *q after the node pointed by pointer *p, and write the key code.

: First connect *q to the node pointed by the original pointer field of *p, and then connect it to p [first connect then, then connect before], the code is as follows:

q->next=p->next;
p->next=q;

Insert image description here


2. Insert a new node pointed to by *q in front of *p in the singly linked list, use temp as the intermediate variable, and write the key code.

: Use the intermediate variable temp to exchange the code part of the data field data, [insert first, then exchange], the code is as follows:

q->next=p->next;
p->next=q;
temp=p->data;	//交换数据域
p->data=q->data;
q->data=temp;

单链表的删控

1. Delete a node pointed to by the predecessors *p and *q in the singly linked list and write the key code.

: The steps of searching and then deleting can be summarized as [locate first, then disconnect and release], point the *q pointer to the node to be deleted, and p is its predecessor node. The code is as follows:

q=p->next;	//先定位,定位删除位置
p->next=q->next;	//断开q与p的连接,p与下一个结点连接
free(q);	//通过free()函数进行释放

Insert image description here


2. Delete the node pointed to by *p in the singly linked list and write the key code.

: By exchanging the data fields of the two pointers, exchanging the data fields of the two pointers, and then deleting the subsequent nodes through the free() function, the code is as follows:

q=p->next;	//先定位,定位删除位置
p->data=p->next->data;	//与后继结点交换数据域data
p->next=q->next;	//断开q与p的连接,p与下一个结点连接
free(q);	//通过free()函数进行释放

7. Insertion and deletion code of double linked list

Introduction to the table

1. In the double linked list, insert node *q after the node pointed by pointer *p, and write the key code.

: The insertion operation of a doubly linked list can be summarized as [connect first, then connect, then connect before]. The code is as follows:

q->next=p->next;
p->next->prior=q;
q->prior=p;
p->next=q;

Insert image description here
double table's removal

1. In the double linked list, delete the node *q after the node pointed by the pointer *p, and write the key code.

:code show as below:

p->next=q->next;
q->next->prior=p;
free(q);

Insert image description here

8. Insertion and deletion code for circular singly linked list

Circulation table introduction

1. In the circular singly linked list, insert node *q after the node pointed by pointer *p, and write the key code.

: The insertion operation of a cyclic singly linked list is similar to that of a singly linked list. It is also [connect first, then connect, then connect before]. The code is as follows:

q->next=p->next;	//先连后
p->next=q;		//再连前

Insert image description here
[Deletion of circular singly linked list]

1. In the circular singly linked list, insert node *q after the node pointed by pointer *p, and write the key code.

: The deletion operation of a cyclic singly linked list is also similar to that of a singly linked list. The deletion steps can be summarized as [locate first, then disconnect and release]. The code is as follows:

q=p->next;	//先定位,定位删除位置
p->next=q->next;	//断开q与p的连接,p与下一个结点连接
free(q);	//free()函数释放结点

Insert image description here

9. Insertion and deletion code for circular doubly linked list

Introduction to the circulation table

1. In the circular double linked list, insert node *q after the node pointed by pointer *p, and write the key code.

: Node p is the predecessor node of new node q. The code is as follows:

q->next=p->next;
p->next->prior=q;
q->prior=p;
p->next=q;

Insert image description here
Circulation double rotation table's removal

1. In the circular double-linked list, delete the node pointed to by *p and write the key code.

: Point the *p pointer to the node to be deleted. The code is as follows:

p->next->prior=p->prior;
p->prior->next=p->next;
free(p);

Insert image description here

Guess you like

Origin blog.csdn.net/qq_43085848/article/details/134000967