Write their own code there are several large use cases have been difficult, the online code most of the problem, the idea is to first put the list of empty tables, and then the list of elements in the loop into the specified position.
Here is a copy of the correct code, but a list of the leading nodes :
void Insertsort (linklist &l) { lnode *p,*q,*r,*u; p=l->next; l->next=null; Empty the table and insert the original linked table nodes into the ordered table one by one while (p!=null) { //When the list is not up to the end and P is the working pointer r=l;q=l->next; while (Q!=null&&q->data<=p->data) { //Check the insertion position of P node in the list, then Q is the working pointer r=q;q=q-> Next; } u=p->next; p->next=r->next; r->next=p; P=u; Link the P node into the list, R is the precursor of Q, and U is the next pointer to the node to be inserted }}
The subject is a linked list without a head node , modified as follows:
void Insertsort (linklist &l) {ListNode *p,*u,*r,*q,*s;/*h2 to point to the node that needs to be inserted, H3 to point to the previous node of H2 p=l->next; l->next=null; Empty table, and then insert the original linked table nodes into the ordered table one by one while (P!=null) {//When the list is not up to the end, p is the working pointer r=l; q=l->next; if (P->val < l->val) {s=l; u=p->next; p->next=l; L=p; P=u; } else {while (q!=null&&q->val<=p->val) {//Check P node insertion position in the list, then Q is the working pointer r=q; q=q->next; } u=p->next; p->next=r->next; r->next=p; P=u; Link the P node into the list, R is the precursor of Q, and U is the next pointer to the node to be inserted}}.
List Insertion Sort (insertion-sort-list)