#include<stdio.h>
#include<stdlib.h>
struct NODE{
int date;
struct NODE *next;
};
typedef struct NODE *list;
list head;
list creat(int t)
{
list newnode,lastnode;
newnode=malloc(sizeof(struct NODE));
newnode->date=t;
newnode->next=NULL;
if(head==NULL) head=newnode;
else{
lastnode=head;
while(lastnode->next!=NULL)
{
lastnode=lastnode->next;
}
lastnode->next=newnode;
}
return head;
}
void print(list h)
{
list node;
node=h;
while(node!=NULL)
{
printf("%d",node->date);
h=node;
node=h->next;
}
}
int main()
{
list h;
int n,i,t;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&t);
h=creat(t);
}
print(h);
return 0;
}
(自用)尾插法
最新推荐文章于 2024-07-25 15:58:50 发布