//怎样把一个链表掉个顺序(也就是反序,注意链表的边界条件并考虑空链表)?
#include <iostream>
using namespace std;
typedef struct node
{
int data;
struct node*next;
}Node,*LinkList;
LinkList& initList(LinkList&L)
{
int a=10;Node *p;int i=0;
L=(Node*)malloc(sizeof(Node));
L->next=NULL;
while(i<10)
{
p=(Node*)malloc(sizeof(Node));
p->data=--a;
p->next=L->next;
L->next=p;
i++;
}
return L;
}
LinkList& reverse(LinkList&L)
{
Node *p,*q,*r;
p=L->next;
q=p->next;
r=q->next;
p->next=NULL;
while(r!=NULL)
{
q->next=p;
L->next=q;
p=q;
q=r;
r=r->next;
}