为生存而奔跑

   :: 首页 :: 联系 :: 聚合  :: 管理
  271 Posts :: 0 Stories :: 58 Comments :: 0 Trackbacks

留言簿(5)

我参与的团队

搜索

  •  

积分与排名

  • 积分 - 319340
  • 排名 - 75

最新评论

阅读排行榜

评论排行榜

#include<iostream>
using namespace std;
struct node
{
 
int data;
 
struct node * next;
}
;
node
* reverse(node * head)
{
 node 
* p1,*p2,*p3;
 p1
=head;
 p2
=p1->next;
 
while(p2!=NULL)
 
{
  p3
=p2->next;
  p2
->next=p1;
  p1
=p2;
  p2
=p3;
 }

 head
->next=NULL;
 head
=p1;
 
return head;
}

node 
* makeNode()
{
 
int n;
 node 
* head,*p,*q;
 head
=(node*)malloc(sizeof(node));
 p
=head;
 cin
>>n;
 
for(int i=1;i<n;i++)
 
{
  scanf(
"%d",&p->data);
  q
=(node*)malloc(sizeof(node));
  p
->next=q;
  p
=q;
 }

 scanf(
"%d",&p->data);
 p
->next=NULL;
 
return head;
 
}

void print(node *head)
{
 
while(head!=NULL)
 
{
  cout
<<head->data<<endl;
  head
=head->next;
 }

}

int main()
{
 print(reverse(makeNode()));
 
return 0;
}


posted on 2009-08-06 10:03 baby-fly 阅读(247) 评论(0)  编辑 收藏 引用 所属分类: Algorithm

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