// LinkList.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
struct Node{
int data;
Node * next;
};
void inverse(Node * & head){
Node * p=head;
Node * q=p->next;
Node *temp=q->next;
q->next=p;
p->next=NULL;
p=q;
q=temp;
while(q!=NULL){
Node *temp=q->next;
q->next=p;
p=q;
q=temp;
}
head= p;
}
int _tmain(int argc, _TCHAR* argv[])
{
Node * head;
Node a;
Node b;
Node c;
Node d;
Node e;
head=&a;
a.data=1;
a.next=&b;
b.data=2;
b.next=&c;
c.data=3;
c.next=&d;
d.data=4;
d.next=&e;
e.data=5;
e.next=NULL;
Node * p=head;
while(p!=NULL){
printf("%d\n",p->data);
p=p->next;
}
//逆置
inverse(head);
p=head;
while(p!=NULL){
printf("%d\n",p->data);
p=p->next;
}
return 0;
}
05-13
10-30
10-13
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交