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

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

2016-07-22 08:52 253 查看
#include<bits/stdc++.h>
using namespace std;
struct node
{
int data;
struct node *next;
}*head,*tail,*p;
int n;
void built()
{
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
while(n--)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=head->next;
head->next=p;
}

}
void print()
{
p=head->next;
while(p)
{
printf("%d",p->data);
if(p->next)
printf(" ");
p=p->next;
}
}
int main()
{
scanf("%d",&n);
built();
print();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: