#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct list
{ int key;
struct list *next;
} node;
void print(node * );
node* reverse(node* );
int main(void)
{
//建表
node *head=NULL;
node *current;
node *prev;
int key;
puts("enter the key(q to quit)");
while(scanf("%d",&key)==1)
{ current=malloc(sizeof(node));
if(head==NULL)
head=current;
else
prev->next=current;
current->next=NULL;
current->key=key;
prev=current;
puts("please enter your key");
}
//打印表
puts("the single list");
print(head);
//反转并打印表
puts("the reverse list");
node *new_head=reverse(head);
print(new_head);
}
void print(node *head)
{
while(head!=NULL)
{ printf("%d\n",head->key);
head=head->next;
}
}
node* reverse(node* head)
{
node* new_head = NULL;
while (head)
{
node* next = head->next;
head->next = new_head;
new_head = head;
head = next;
}
return new_head;
}