给定程序中已建立一个带有头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数 fun 的功能是把形参 x 的值放入一个新结点并插入到链表中,插入后各结点仍保持递增有序。
#include<stdio.h>
#define N 8
typedef struct list{
int data;
struct list *next;
} SLIST;
void fun(SLIST *h, int x){
SLIST *p,*q,*s;
s=(SLIST *)malloc(sizeof(SLIST));
/**********found**********/
s->data=x;
q=h;
p=h->next;
while(p!=NULL &&x>p->data){
/**********found**********/
q=p;
p=p->next;
}
s->next=p;
/**********found**********/
q->next=s;
}
SLIST*creatlist(int *a) {
SLIST *h,*p,*q;
int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0; i<N; i++)