Today, continue to be sorted by the chain form. The day before yesterday, everyone has it. Don't understand it, it is going to come slowly, and you can't come.
P = h-> next; h-> next = null;
While (p)
{
IF (P-> Data
{
Q = P-> next;
P-> next = H;
H = p; p = q;
}
Else
{
q = h; r = q-> next;
While (R && P-> Data> R-> DATA)
{
q = r; r = r-> next;
}
Q-> next = p; p = p-> next;
Q-> Next-> Next = R;
}
}
According to the idea of this procedure, let's think about the entire process, this program is divided into two parts, part of the node value to be sorted is smaller than the node value of the head, put it in the first one. , Because if the one of the comparative head is already less than it, it should not be compared. If the node value to be inserted is not less than the current header node, then you should find the right position to insert the node, let's see what Q and R pointer are used to do, it points to the head Pointers h and r point to Q pointers, because we know that the shortcomings of the one-way linked list cannot know what it is in front of it, so it may be guided to the linked list. Our purpose is to use Q to save its previous node. There are two possibilities in the While cycle, one is R is empty, where R is empty, explaining that this linked list is already the last one, so the junction that is inserted directly is inserted. As for P-> Data> r-> DATA is to wait for P-> Data than r-> Data hours, you can continue to insert down the steps of the insertion. The While is that if these two conditions are true, the explanation has not found yet, then the two double-chain pointers will be moved afterwards, and then they can be inserted.
If you are still ambiguous, you don't want it, then look at the following procedure:
Struct node * li_sort (struct node * h)
{
Struct node * t, * s, * u, * v;
S = H-> next;
H-> next = NULL;
While (s! = NULL)
{
For (t = s, v = H; v! = null && v-> data
S = S-> Next;
IF (v == h) h = t;
Else U-> next = T;
T-> next = V;
}
}
We can see that this program is very similar to it, but it is more simplified, and the entire judgment is in a for statement. Let's take a look at this program, I believe that if you think about it, everyone should understand. S = H-> Next and H-> Next = NULL These two sentences are the same, and they separate them into partned part and to be sorted. Following the main thing to see the for statement, because all judging conditions are here. Here T is the temporary variable generation S, the role of S is the node, V and U pointers that are currently inserted, and Q and R of the above programs are the disadvantages of the unidirectional linked list. The conditions here are the same, and the above programs are the possibility of integrating two cases, followed by the following procedure, which is the insertion head or in the middle. Ok, or I want my own brain to think,
Here's 16th day, there is a whole process.
Of course, the one-way linked list is to talk about the two-way linked list, because the two-way linked list can go forward, so the program is better, but it is the insertion and deletion of it, and it is another practice Link list operation. Opportunity. Everyone thinks yourself, try to write the procedure, with the basis of the above one-way linked list should be easy to follow the idea. Everyone sends a good program to http://zhgpa.vicp.net/bbs programmer exam, see where everyone's way is discussed. Don't see the procedures I:
Some definitions
While (p)
{
For (q = p-> pre, r = p; Q && P-> Data
P = P-> next;
R-> pre-> next = p;
IF (p) p-> pre = r-> pre;
IF (q)
{
P-> next = Q-> next;
IF (q-> next) q-> next-> pre = p;
P-> pre = q;
Q-> next = P;
}
Else
{
R-> Next = H;
R-> pre = null;
H-> pre = r;
}
}
Ok, what is your program? I hope everyone will discuss it. Although the contents of learning in these days, it is absorbed by a lot of experience, and now the operation of the list is more step forward. I know some ways to analyze the program. Programming this road is really long. I don't understand anything in this road, but I will stick to it.