逆序建立链表
2016-10-02 15:09
211 查看
#include<stdio.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
};
struct node *creat(int n)
{
struct node *head,*tail,*p;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
int i;
for(i=0;i<n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=head->next;
head->next=p;
}
return head;
}
void print(struct node *head)
{
struct node *p;
p=head->next;
while(p!=NULL)
{
if(p==NULL)
printf("%d",p->data);
else printf("%d ",p->data);
p=p->next;
}
}
int main()
{
int n;
struct node *head;
scanf("%d",&n);
head=creat(n);
print(head);
printf("\n");
return 0;
}
相关文章推荐
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- SDUT_2015寒假集训_结构体练习_J-逆序建立链表
- 逆序建立链表
- 数据结构——链表之逆序建立链表
- SDUT 2117 数据结构实验之链表二:逆序建立链表
- 逆序建立链表 分类: 链表 2015-06-07 12:46 10人阅读 评论(0) 收藏
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- 单链表的动态建立和逆序输出
- 基于链表:键盘输入若干个整数,按输入数据逆序建立一个带头结点的单链表
- 华为机试题(8)--单向链表的建立,反转(逆序),遍历显示,删除
- 数据结构实验之链表二:逆序建立链表
- 数据结构实验之链表二:逆序建立链表
- sdut2117数据结构实验之链表二:逆序建立链表
- [SDUT](2117)数据结构实验之链表二:逆序建立链表 ---链式存储(线性表)
- SDUT 2117数据结构实验之链表二:逆序建立链表