Dynamic Link List Head Insertion Method and Dynamic Tail Insert Method

First of all, this dynamic head insertion method is equivalent to a classroom. 1. If there are no students in the classroom at the beginning, we have to create and recruit a student in, and then continue to recruit people in. Every time a student comes in, I will let new people come in. Sit at the front.
So
1. There are no students in the classroom
if (head == NULL)
{
head = new; //new is where we enter the data to store
return head;
}
This
creates the first student to come in.
the else
{ New-> the Next = head; head = new new; return head; } This finish




has become a person every move made him sit in the front.

Insert picture description here
Insert picture description here

Insert picture description here

The dynamic tail insertion method is that a classroom finds students to sit back continuously. Let the newcomer sit behind the newcomer.
We also had to create (recruit students) to come in if there were no students at the beginning, and then constantly let the new students come in behind the previous ones. So define a pointer to traverse the linked list to the tail, and then insert the students.
Insert picture description here

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_47457689/article/details/107376584