梅麻吕游戏资源百度云:各位c高手看看这个链表中的h指针代表啥?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/02 10:16:58
#include <stdio.h>
#include <stdlib.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));
s->data=x;
q=h;
p=h->next;
while(p!=NULL && x>p->data) {
q=p;
p=p->next;
}
s->next=p;
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++)
{ q=(SLIST *)malloc(sizeof(SLIST));
q->data=a[i]; p->next=q; p=q;
}
p->next=0;
return h;
}
void outlist(SLIST *h)
{ SLIST *p;
p=h->next;
if (p==NULL) printf("\nThe list is NULL!\n");
else
{ printf("\nHead");
do { printf("->%d",p->data); p=p->next; } while(p!=NULL);
printf("->End\n");
}
}
main()
{ SLIST *head; int x;
int a[N]={7,12,15,18,19,25,29,37};
head=creatlist(a);
printf("\nThe list before inserting:\n"); outlist(head);
printf("\nEnter a number : "); scanf("%d",&x);
fun(head,x);
printf("\nThe list after inserting:\n"); outlist(head);
}


h指针代表链表头接点。他指向连表的头接点。
你不是在main里这样写了么:SLIST *head
生成了一个指针,用来代表头节点。
调用outlist(head); 函数时,说明了对head连表操作

h只是SLIST定义的一个指针 你在这可以认为变量
调用这个fun(head,x)而用了它

结构体变量 slist的头指针