#include<iostream>
#include<malloc.h>
using namespace std;
struct node
{
int data;
struct node *next;
};
struct node *creat(int n)
{
struct node *head,*tail,*p;
int i;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
for(i=1;i<=n;i++)
{
p=(struct node *)malloc(sizeof (struct node ));
cin>>p->data;
p->next=head->next;
head->next=p;
}//游动指针p指向p的前一个
return head;
};
void display(struct node *head)
{
struct node *q;
q=head->next;
while(q!=NULL)
{
cout << q->data;
if(q->next!=NULL)
cout<< " ";
q=q->next;
}
cout<<endl;
}
int main()
{
int n,h;
struct node *head;
cin >>n;
head=creat(n);
display(head);
return 0;
}
2117数据结构实验之链表二:逆序建立链表
最新推荐文章于 2019-02-14 18:36:06 发布