#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node*next;
};
struct node * creat(int n)
{
struct node *head,*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));
scanf("%d",&p->data);
p->next=NULL;
p->next=head->next;
head->next=p;
}
return (head);
}
void print(struct node * head)
{
struct node *p;
p=head->next;
while(p!=NULL)
{
printf("%d",p->data);
if(p->next!=NULL)
{
printf(" ");
}
else
{
printf("\n");
}
p=p->next;
}
}
int main()
{
int N;
struct node * head;
scanf("%d",&N);
head=creat(N);
print(head);
return 0;
}
数据结构之逆序建表
猜你喜欢
转载自blog.csdn.net/qq_41341757/article/details/81746225
今日推荐
周排行