建立并输出一个简单的列表

linux1304 2007-04-24 02:20:52
#include "stdio.h"
struct list{char data;
struct list *next;

};
struct list *create_list()
{struct list *n,*p,*q;
char ch;
h=(struct list *)malloc(sizeof(struct list));
p=q=h;
ch=getchar();
while(ch='*')
{p=(struct list *)malloc(sizeof(struct list));
p->data=ch;
q->next=p;
q=p;
ch=getchar();
p->next=NULL;
return h;
}
void print_list(h)
struct list *h;
{struct list *p;
p=h;
printf("head");
p=p=->next;
while(p!=NULL)
{printf("->%c",p->data);
p=p=->next;}
}printf("\n");
main()
{struct list *head;
head=create_list();
print_list(head);
}
...全文
154 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
blue_coco 2007-04-24
  • 打赏
  • 举报
回复
#include "stdio.h"
struct list{char data;
struct list *next;
};

struct list *create_list()
{
struct list *h,*p,*q;
char ch;

h=(struct list *)malloc(sizeof(struct list));
p=q=h;

ch=getchar();
while(ch=='*')
{
p=(struct list *)malloc(sizeof(struct list));
p->data=ch;
q->next=p;
q=p;
ch=getchar();
p->next=NULL;
}
return h;
}

void print_list(h)
struct list *h;
{
struct list *p;
p=h;
printf("head");
p=p->next;
while(p!=NULL)
{
printf("->%c",p->data);
p=p=->next;
}
printf("\n");
}

main()
{
struct list *head;
head=create_list();
print_list(head);
}

69,380

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧