#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef struct link{
int data;
struct link *next;
}node;
int main()
{
int n,i,a[10];
node *p,*q,*c,*head=NULL;
scanf("%d",&n);
for(int i = 1; i <= n; i++)//创建链表
{
p = (node*)malloc(sizeof(node));//分配空间
p->next = NULL;//将下一个节点为NULL,当最后一个节点完成,结束
scanf("%d",&p->data);
if(head == NULL)
head = p;
else
q->next = p;//图一解释
q = p;
}
//链表的逆序
p = head;//保住头结点
q = p->next;//见图二
while(q)
{
c = q->next;
q->next = p;
p = q;
q = c;
}
head->next=NULL;//原来头结点已经变成末尾,现在它的下一个为空
head=p;//p是逆序后的新头结点,再次将head变为头结点
while(head)
{
printf("%d",head->data);
head=head->next;
}
head=p;//删除
while(head)//见图三
{
q=head->next;
free(head);
head=q;
}
return 0;
}