#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
int data;
struct Node *next;
}node;
node *create(int n)
{
node *head,*p;
int i;
head=(node *)malloc(sizeof(node));
head->next=NULL;
for (i=0;i<n;i++)
{
p=(node *)malloc(sizeof(node));
scanf("%d",&p->data);
p->next=head->next;
head->next=p;
}
return (head);
}
void output(node *head)
{
node *p;
p=head->next;
while (p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
int main()
{
int n;
node *head;
scanf("%d",&n);
head=create(n);
output(head);
return 0;
}
SDUT 2117 数据结构实验之链表二:逆序建立链表
最新推荐文章于 2022-04-09 21:02:11 发布