功能是将一个单链表倒置 , 就是将最后一个点作为第一个,倒数第2个点最为第2个,依次类推
#include <stdio.h>struct link{
int num;
struct link *next;
};
struct link * revers(struct link *p)
{
struct link *q,*r,*d;
d=p;
q=p;
r=p;
p=p->next;
while(p->next!=NULL)
{
q=p;
p=p->next;
q->next=r;
r=q;
}
d->next=NULL;
p->next=q; return p;}main()
{
struct link a,b,c,*p,*q;
a.num=1;
b.num=2;
c.num=3; p=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
q=revers(&p); do
{
printf("%d\n",q->num);
q=q->next;
}
while (q->next!=NULL);}
#include <stdio.h>struct link{
int num;
struct link *next;
};
struct link * revers(struct link *p)
{
struct link *q,*r,*d;
d=p;
q=p;
r=p;
p=p->next;
while(p->next!=NULL)
{
q=p;
p=p->next;
q->next=r;
r=q;
}
d->next=NULL;
p->next=q; return p;}main()
{
struct link a,b,c,*p,*q;
a.num=1;
b.num=2;
c.num=3; p=&a;
a.next=&b;
b.next=&c;
c.next=NULL;
q=revers(&p); do
{
printf("%d\n",q->num);
q=q->next;
}
while (q->next!=NULL);}
0X0040b866 指令引用的 0x00000007 内存。 该内存不能为 “read”
定义:
1、struct link * revers(struct link *p)
2、struct link a,b,c,*p,*q;
调用函数:
q=revers(&p);
明显不行啊。