#include <iostream>
#include <stdlib.h>
#define MAX 5
using namespace std;
typedef struct node
{
int num;
struct node* pnext;
}qnode,*pnode;
pnode init()
{
pnode head;
head=(pnode)malloc(sizeof(qnode));
head->pnext=NULL;
return head;
}
void puts(pnode head,int e)
{
pnode q,p;
q=head;
while(q->pnext!=NULL)
{
q=q->pnext;
}
p=(pnode)malloc(sizeof(qnode));
p->num=e;
p->pnext=NULL;
q->pnext=p;
}
pnode rotate(pnode head)//新建一个链表head_,把head的第一个结点放入head_,head指向下一个结点
{
pnode head_,q;
head_=init();
while(head->pnext!=NULL)
{
q=head->pnext;
head->pnext=q->pnext;
q->pnext=head_->pnext;
head_->pnext=q;
}
return head_;
}
void traverse(pnode head)
{
pnode q=head->pnext;
while(q!=NULL)
{
cout<<q->num;
q=q->pnext;
}
}
int main()
{
pnode head,head_;
head=init();
puts(head,1);
puts(head,2);
puts(head,3);
head_=rotate(head);
traverse(head_);
return 0;
}
http://www.cnblogs.com/pianoid/archive/2011/05/03/reverse-a-singly-linked-list.html
3.12(反转单结点)
最新推荐文章于 2017-03-20 23:06:13 发布