675508756
新新人类
帖子
39
精华
0
无忧币 52
积分 63
阅读权限 20
|
发表于:2008-4-12 20:14
标题:有没有在学数据结构的啊 给大家一个创建链表的代码
<上一帖 |
下一帖>
#include "stdio.h"
#include"stdlib.h"
/*#include "conio.h" */
typedef int elemtype;
typedef struct node
{elemtype data;
struct node *next;
}linklist;
linklist *creatlist()
{
char ch;
int x;
linklist *head,*r,*p;
p=malloc(sizeof(linklist));
p->next=NULL;
head=p;
r=p;
printf("please input data=");
scanf("%d",&x);
while(x!=-1)
{
p=malloc(sizeof(linklist));
p->data=x;
p->next=NULL;
r->next=p;
r=r->next;
printf("input node data: ");
scanf("%d",&x);
}
return(head);
}
void showlist(linklist *p1)
{
linklist *node;
node = p1->next;
while(node){
printf(" %d->",node->data);
node=node->next;
}
}
main()
{
linklist *q;
q=creatlist();
showlist(q);
getch();
}
|
 论坛活动:测测你对IT技术大会的了解指数(赠微软礼品、无忧币) |
|