
#include <stdio.h>
#include <stdlib.h>
struct node
{
int num;
struct node *next;
};
struct node *createReverseList()
{
int x;
struct node *head = NULL;
while (1)
{
scanf("%d", &x);
if (x == 0)
return head;
struct node *p = (struct node *)malloc(sizeof(struct node));
p->next = head;
p->num = x;
head = p;
}
}
void printList(struct node *head)
{
struct node *p = head;
while (p)
{
printf("%d ", p->num);
p = p->next;
}
printf("\n");
}
void deleteList(struct node *head)
{
struct node *p = head;
while (p)
{
struct node *q = p;
p = p->next;
free(q);
}
}
int main()
{
struct node *list = createReverseList();
printList(list);
deleteList(list);
return 0;
}