c语言问题 急急~~

来源:百度知道 编辑:UC知道 时间:2024/06/22 15:02:25
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
{ int data;
struct list *next;
} SLIST;

void fun( SLIST *p)
{ SLIST *t, *s;
t=p->next; s=p;
while(t->next != NULL)
{ s=t;
/**********found**********/
t=t->next;
}
/**********found**********/
printf(" %d ",s);
s->next=NULL;
/**********found**********/
free(t);
}
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("

fun函数是将p所指的数据一一打印出来(运用指针移动)。直到p->nxet为空为止。释放t。
运用了指针和线性链表的知识。
顺便说一句:这是二级C的改错题吧。要考二级可得抓紧时间学了。

说实话。。。建议不要深究这个程序。。写这个程序的人只是想显示他对指针的熟悉,顺便告诉你,他知道结构的嵌套定义。
用一个很不清晰的方法去干了一件很简单的事。。。

赞同

不喜欢这种耍宝的程序,