给定的程序中,函数 fun 的功能是将带头结点的单向链接逆置。即若原链表中从头至尾的数据域依次为;2,4,6,8,10,逆置后,从头到尾的数据域依次为:10、8、6、4、2。
#include<stdio.h>
#define N 5
typedef struct node{
int data;
struct node *next;
}NODE;
void outlist(NODE *h);
void fun(NODE *h){
NODE *p,*q,*r;
/************found***********/
p=h->next;
/**********found*********/
if(p==NULL) return;
q=p->next;
while(q){
r=q->next;
q->next=p;
/**********found**********/
p=q;
q=r;
};
h->next->next=NULL;
h->next=p;
}
NODE *creatlist(int a[]){
NODE *h,*p,*q;
int i;
h=(NODE*)mal