1、编程实现单链表的建立、插入、删除和查找算法,语言采用C或JAVA等。

如题所述

/*P33用头插法建立带头结点的单链表*/
#include "stdio.h"
#define NULL 0
#define LEN sizeof(linklist)
typedef struct node
{int data;
struct node *next;
}linklist;
linklist *head;

void hhead_creat()/*用头插法建立带头结点的单链表*/
{int x;
linklist *p;
head=(struct node*)malloc(LEN);
head->data=-999;
head->next=NULL;
printf("\n\n\t\t请随机输入一组正整数以0作为结束符:\n\n\t\t");
scanf("%d",&x);
while(x!=0)
{ p=(struct node*)malloc(LEN);
p->data=x;
p->next=head->next;
head->next=p;
scanf("%d",&x);
}
}/*hrear_creat*/

void print_linklist(head)/*打印该链表*/
linklist *head;
{linklist *p;
int n=0;
p=head->next;
printf("\n\n\t\t");
while(p!=NULL)
{ printf("%5d",p->data);
p=p->next; n=n+1;
if((n+1)%10==0) printf("\n\t\t");
}
}/*print_linklist*/

main()
{hhead_creat(head);
print_linklist(head);
}

参考资料:《数据结构》田鲁怀编写 电子工业出版社(本人编写的书)

温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-12-20
sdgfn;ksdg
第2个回答  2020-07-06
sdgfn;ksdg
再看看别人怎么说的。
相似回答