Chinaunix首页 | 论坛 | 博客
  • 博客访问: 82414
  • 博文数量: 17
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 290
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-17 21:47
文章分类

全部博文(17)

文章存档

2011年(1)

2008年(16)

我的朋友
最近访客

分类: 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;   
}  

阅读(934) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~