分类: C/C++
2008-03-12 21:17:14
#include "stdlib.h"
#include "stdio.h"
typedef struct node
{
int n;
node* next;
}Node;
void ReverseOrder(struct node**);
void Print(struct node *);
void main()
{
Node* head=(Node*)malloc( sizeof(Node));
head->n=0;
head->next=NULL;
Node* cur=head;
for(int i=1; i<10;i++)
{
Node* p= (Node*)malloc( sizeof(Node));
p->n=i;
p->next=NULL;
cur->next=p;
cur=p;
}
Print(head);
ReverseOrder(&head);
Print(head);
}
void Print(Node* head)
{
Node* p=head;
while(p)
{
fprintf(stdout,"%d\t",p->n);
p=p-> next;
}
printf("\n");
}
void ReverseOrder(Node** head)
{
Node* h=*head;
Node* cur=h->next;
Node* next;
while(cur)
{
next=cur-> next;
cur-> next=h;
h=cur;
cur=next;
}
(*head)-> next=NULL;
*head=h;
}