2007年10月31日

#include<stdio.h>
#include
<stdlib.h>
#define ELEMTP int
#define M 5

struct node *p,*s;
struct node *head;
struct node
{
  ELEMTP data;
  
struct node *next;
}

main()
void creat();
  
void nizhi(struct node *head);
  
void outlin(struct node *h); 
  creat();
  nizhi(head);
  outlin(head);
}

void creat()
{int i=1;
 
int x=NULL;
 head
=(node *)malloc(sizeof(node));
 head
->next=NULL;p=head;
 
while(i!=(M+1))
 
{printf("Please input the %d number:",i);scanf("%d",&x);
  s
=(node*)malloc(sizeof(node)); 
  s
->data=x;s->next=NULL;
  p
->next=s;
  p
=s;
  i
++;
 }

}
 
void nizhi(struct node *head)
{ p=head->next;
  head
->next= NULL;
  
while(p!=NULL)
  
{s=p->next;
   p
->next=head->next;
   head
->next=p;
   p
=s;
  }
 
}
  
void outlin(struct node *h)
{ p=h->next;
  
while(p!=NULL)
  
{printf("data=%5d\n",p->data);
   p
=p->next;
  }
 
  printf(
"\noutput\n\n");
}
 

posted @ 2007-10-31 16:40 天涯沦落人 阅读(1261) | 评论 (3)编辑 收藏


仅列出标题  

posts - 2, comments - 3, trackbacks - 0, articles - 0

Copyright © 天涯沦落人