链表逆置c语言代码

#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");
}
 

你可能感兴趣的:(链表逆置c语言代码)