#include <stdio.h>
#include <stdlib.h>
struct node
{
int date;
struct node *next;
};
struct node *head,*q;
int main()
{
head=(struct node *)malloc(sizeof(struct node ));
head->next=NULL;
int i,len;
scanf("%d",&len);
for(i=0;i<len;i++)
{
q=(struct node *)malloc(sizeof(struct node ));
scanf("%d",&q->date);
q->next=NULL;
q->next=head->next;
head->next=q;
}
q=head->next;
while(q!=NULL)
{
printf("%d ",q->date);
q=q->next;
}
return 0;
}
逆序建链表区别于顺序建链表就是逆序建链表将写进来的数按照相反的顺序输出!
#include <stdlib.h>
struct node
{
int date;
struct node *next;
};
struct node *head,*q;
int main()
{
head=(struct node *)malloc(sizeof(struct node ));
head->next=NULL;
int i,len;
scanf("%d",&len);
for(i=0;i<len;i++)
{
q=(struct node *)malloc(sizeof(struct node ));
scanf("%d",&q->date);
q->next=NULL;
q->next=head->next;
head->next=q;
}
q=head->next;
while(q!=NULL)
{
printf("%d ",q->date);
q=q->next;
}
return 0;
}
逆序建链表区别于顺序建链表就是逆序建链表将写进来的数按照相反的顺序输出!