问题 问答题

采用单链表作为存储结构,试编写一个函数来实现用选择排序方法进行升序排列。

答案

参考答案:

解析:首先定义单链表的结点: struct node {int key; struet node*link; } 函数如下: struct*selectsort(struct node*h) {struet node*P,*q,*r,*s,*t; t=Null; while(h!=Null) {p=h; q=Null; s=h; r=Null; while(P!=Null) {if(p—>key<s—>key) {s=p; p=q; } q=p; p=p—>link; } if(s==h) h=h—>link; else h=s; s—>lind=t; t=s; } h=t; return(h); }

单项选择题
问答题 简答题