#include<stdio.h>
typedef struct node
{
int data;
node* next;
}node;
node* CreateList()
{
node* head = NULL, *pnew = NULL, *ptail = NULL;
pnew = (node*)malloc(sizeof(node));
pnew->next = NULL;
while (1 == scanf("%d", &pnew->data))
{
if (head == NULL)
{
head = pnew;
}
else
{
ptail->next = pnew;
}
ptail = pnew;
pnew = (node*)malloc(sizeof(node));
pnew->next = NULL;
}
free(pnew);
pnew = NULL;
return head;
}
void show(node* t)
{
if (t != NULL)
{
if (t->next != NULL)
{
show(t->next);
}
printf("%d ", t->data);
}
}
int main()
{
node* head;
head=CreateList();
node* t = head;
show(t);
return 0;
}
剑指offor面试题5:从尾到头打印链表
最新推荐文章于 2024-02-28 18:26:20 发布