给定程序中,函数 fun 的功能是在带有头结点的单向链表中,查找数据域中值为 ch 的结点。找后通过函数值返回该结点在链表中所处的顺序号;若不存在值为 ch 的结点,函数返回0值。
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct list{
int data;
struct list *next;
} SLIST;
SLIST *creatlist(char*);
void outlist(SLIST*);
int fun(SLIST *h,char ch){
SLIST *p;
int n=0;
p=h->next;
/**********found**********/
while(p!=0) {
n++;
/**********found**********/
if (p->data==ch)return n;
else p=p->next;
}
return 0;
}
void main(){
SLIST *head;
int k;
char ch;
char a[N]= {'m','p','g','a','w','x','r','d&#