C语言,编程题,在线等

来源:百度知道 编辑:UC知道 时间:2024/06/06 21:01:30
编写程序生成10个2位随机数并从小到大排序.然后在这些树中插入一个数和删除一个数,使它们仍然保持有序.

要求调用函数
要编好的程序

//---------------------------------------------------------------------------

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

typedef struct dt{
int data;
struct dt *next;
}dlist;/*链表结构*/

void prt(dlist *a)/*输出链表元素*/
{
while (a!=NULL){
printf("%d\t",a->data );
a=a->next ;
}
putchar('\n');
}

dlist *ins(int n,dlist *a)/*插入元素*/
{
dlist *c;
if (a==NULL) {
c=malloc(sizeof(dlist));
c->data =n;
c->next =NULL;
return c;
}
else if (n<=a->data ) {
c=malloc(sizeof(dlist));
c->data =n;
c->next =a;
return c;
}
else{
a->next=ins(n,a->next );
}
return a;
}
dlist *rm(int n,dlist *a)/*删除元素*/
{
dlist *t=a;
if (a==NULL) {
printf("not found!\n");