pta_链表的插入排序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| void insertion_sort(LinkNode *&L) { LinkNode *p; LinkNode *pre; p=L->next->next; LinkNode *q; L->next->next=NULL; pre=L->next; LinkNode *z=L; while(p) { q=p->next; while(pre&&pre->data<p->data) { z=pre; pre=pre->next; } p->next=pre; z->next=p; p=q; } }
|