链表逆置c语言代码

Posted on 2007-10-31 16:40 天涯沦落人 阅读(1262) 评论(3)  编辑 收藏 引用
#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");
}
 

Feedback

# re: 链表逆置c语言代码  回复  更多评论   

2007-11-01 13:55 by Minidx全文检索
咳……这个代码……也太小学生了吧?

# re: 链表逆置c语言代码  回复  更多评论   

2007-11-19 14:49 by 天涯沦落人
俺刚在学数据结构。不好意思。做什么都是从头开始的

# re: 链表逆置c语言代码  回复  更多评论   

2007-11-26 12:16 by 无知者无畏
我连搞你这个代码都有问题

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


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

Copyright © 天涯沦落人