AB descending list merge algorithm (first interpolation)
On an AB list talked merge, but merge with our AB is the order merge, this section we need to do the reverse order of how the list merge AB
Before we talk about the head plug insertion method is reverse insert mode, then head interpolation algorithm whether this can be done, of course, you can focus on this question is this.
Concrete steps I have written a note, please take a look at
1 // descending merge A and B is C 2 / * . 3 embodiment the interpolation is done with the head, . 4 * / . 5 void Merge (LNode * A, * B LNode, LNode * C) { . 6 LNode * P = A- > Next; . 7 LNode the B-* Q => Next; . 8 LNode * S; . 9 C = a; 10 the C-> Next = NULL; // NULL value is intentional . 11 Free (B); 12 is the while (P ! = NULL && Q! = NULL) { // with the while (Q && Q) 13 is IF (p-> Data <Q- => Data) { 14 P = S; // S = PS pointer on the smallest P 15 P = p-> Next; // P moves rearward under a preparation for the next comparison 16 S-> Next the C-=> Next; // head interpolation the C-> next assignment to S-> Next . 17 C-> next = S; // C to establish contact with s, corresponding to the arrows marked 18 is } . 19 the else { // ibid 20 is S = Q; 21 is Q = Q- > Next; 22 is S-> Next the C-=> Next; 23 is the C-> Next = S; 24 } 25 } 26 is while (! P = NULL) { // this need while loop that reason, because the first interpolation method, 27 S = P; // needs to forward insertion of one 28 P = p-> Next ; 29 S-> Next the C-=> Next; 30 the C-> Next = S; 31 is } 32 the while (! Q = NULL) { 33 is S = Q; 34 is Q = Q-> Next; 35 S-> Next = the C-> Next; 36 the C-> Next = S; 37 [ } 38 }