您的位置:首页 > 理论基础 > 数据结构算法

sdut2117数据结构实验之链表二:逆序建立链表

2016-11-06 15:06 211 查看
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
int main()
{
int i,n;
struct node *head,*p;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
scanf("%d",&n);
for(i=0;i<n;i++)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=head->next;
head->next=p;
}
while(p)
{
printf("%d ",p->data);
p=p->next;
}
return 0;
}

/***************************************************
User name: TJRAC6015203228魏杰
Result: Accepted
Take time: 0ms
Take Memory: 104KB
Submit time: 2016-11-01 13:31:00
****************************************************/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: