链表之顺序建链表
2016-07-20 16:17
323 查看
#include <stdio.h>
#include <malloc.h>
struct node
{
int data;
struct node *next;
};
struct node *creat(struct node *head)
{
int n;
scanf("%d",&n);
struct node *p,*tail;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
int i;
for(i=1;i<=n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
tail->next=p;
tail=p;
}
return (head);
}
void main()
{
struct node *head,*p;
head=creat(head);
p=head->next;
while(p->next)
{
printf("%d ",p->data);
p=p->next;
}
printf("%d\n",p->data);
}
#include <malloc.h>
struct node
{
int data;
struct node *next;
};
struct node *creat(struct node *head)
{
int n;
scanf("%d",&n);
struct node *p,*tail;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
int i;
for(i=1;i<=n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
tail->next=p;
tail=p;
}
return (head);
}
void main()
{
struct node *head,*p;
head=creat(head);
p=head->next;
while(p->next)
{
printf("%d ",p->data);
p=p->next;
}
printf("%d\n",p->data);
}
相关文章推荐
- 【java|Android接口回调】小小猿理解的接口回调
- 关于Django ORM filter方法小结
- 红黑树
- 限制UITextField的输入字数(长度)最正确的方法
- codeforces水题100道 第六题 Yandex.Algorithm 2011 Qualification 2 A. Double Cola (math)
- leetcode 45. Jump Game II
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- 【笔记】iOS开发用到的一些终端的命令
- android UI 效果资源
- CPU流水线的探秘之旅
- StingUtils的常用方法
- 每日安全简讯20160720
- Temp segment 使用的一些总结
- Android 让WebView完美支持https双向认证(SSL)
- Linux下编译GDAL
- java学习之checkbox和choice
- 杭电1222
- Cow Marathon(两次dfs求树的直径)
- <mvc:default-servlet-handler />过滤器拦截静态资源
- 第17周 啊哈算法 图的遍历算法-Dijkstra单源最短路径算法