双链表的实现
【摘要】 #include <stdio.h>#include <string.h>#include <stdlib.h>#define N 10typedef struct node{ char name[20]; struct node *llink,*rlink;}stud;/*双链表的结构定义*/ /*双链表的创建*/stud * creat...
-
#include <stdio.h>
-
#include <string.h>
-
#include <stdlib.h>
-
#define N 10
-
typedef struct node
-
{
-
char name[20];
-
struct node *llink,*rlink;
-
}stud;/*双链表的结构定义*/
-
-
/*双链表的创建*/
-
stud * creat(int n)
-
{
-
stud *p,*h,*s;
-
int i;
-
if((h=(stud *)malloc(sizeof(stud)))==NULL)
-
{
-
printf("cannot find space!\n");
-
exit(0);
-
}
-
h->name[0]='\0';
-
h->llink=NULL;
-
h->rlink=NULL;
-
p=h;
-
for(i=0;i<n;i++)
-
{
-
if((s= (stud *) malloc(sizeof(stud)))==NULL)
-
{
-
printf("cannot find space!\n");
-
exit(0);
-
}
-
p->rlink=s;
-
printf("Please input the %d man's name: ",i+1);
-
scanf("%s",s->name);
-
s->llink=p;
-
s->rlink=NULL;
-
p=s;
-
}
-
h->llink=s;
-
p->rlink=h;
-
return(h);
文章来源: chenyu.blog.csdn.net,作者:chen.yu,版权归原作者所有,如需转载,请联系作者。
原文链接:chenyu.blog.csdn.net/article/details/50565072
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)