一道简单的数据结构问题

来源:百度知道 编辑:UC知道 时间:2024/05/13 02:27:31
以链表作为文件的存储结构,对其实现起泡排序和直接选择排序,要准确的答案
这个也太多了,要简单点的如:
以数组为存储结构,实现其直接插入排序
INSERTSORT(R)
rectype R[];
{ int i,j;
for(i=2;i<n;i++)
{ R[0]=R[i];
j=i-1;
while(R[0].key<R[j].key)
R[j+1]=R[j--];
R[j+1]=R[0];
}
}

大哥,链表的操作有些时候比数组麻烦的多,我收藏的这两个算是写得比较好的程序了,代码应该精简不了多少
————————————————
刚好我有收藏

起泡排序:
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>

typedef int DATA;
#define LINK_SIZE 20

struct node{
DATA data;
struct node *next;
};

struct node* head=NULL;

int init_link();
int output_link(struct node* head);
int clean_link(struct node* head);
int myrand(int seed);
struct node* bubble(struct node* lhead);

int main(void){
init_link();

output_link(head);

head = bubble(head);
printf("\nxxxxxxxxxxxx\n\n");
output_link(head);
/*clean memory*/
clean_link(head);

return 0;
}/*end of main*/

int init_link(){
int i=0;
struct node* tmp_node;
for(; i<LINK_SIZE; i++){
tmp_no