已知带头结点的动态单链表L的结点是按整数值递增排列的,试写一算法将值为x的结点插入表L中,使L仍然有序。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include

#include

typedef struct node

{

int data;

struct node *next;

}*Listlink;

void

qian_create(Listlink *head,int n)

{

int i;

Listlink p;

*head=(Listlink )malloc(sizeof(struct node)); (*head)->next=NULL;

printf("头插法\n input %d numbers:\n",n); for(i=0;i

{

p=(Listlink)malloc(sizeof(struct node)); scanf("%d",&(p->data));

p->next=(*head)->next;

(*head)->next=p;

}

}

void print_list(Listlink head)

{

Listlink p;

p=head->next;

while(p!=NULL)

{

printf(" %d",p->data);

p=p->next;

}

}

main()

{

Listlink la,lc;

qian_create(&la,10);

print_list(la);

getchar();

system("pause");

}

经过codeblocks 检验完全可以运行。适用于数据结构2.5 习题

————adam

相关文档
最新文档