//单链表的直接插入排序 void InsertSort(LinkList &L){ LNode *p=L->next; LNode *q,*r; if(p!=null){//原单链表中有一个或多个结点 r=p->next;//保存p结点的后继结点 p->next=null; p=r; while(p!=null){ r=p->next; q=L; while(q->next!=null && q->next->data<p->data){ q=q->next;//在有序表中找插入p的前驱结点q } p->next=q->next; q->next=p; p=r; } } }
设计一个算法,实现在一个带表头结点的单链表上的简单选择排序算法 单链表中每个结点2个域:data和link,要求先使用类型说明准确描述你所使用的单链表存储表示 */ typedef struct LNode{ int data; struct LNode* next; }LinkList; void LinkList_Select_Sort(LinkList &L){ LNode *p,*q,*r; int e,temp; for(q=L->next;q!=null;q=q->next){ e=q->data; r=q; for(p=p->next;p;p=p->next){ if(e>p->data){ e=p->data; r=p; } } temp=q->data; q->data=r->data; r->data=temp; } }