问题
填空题
以下程序中函数fun的功能是:构成一个如图所示的带头节点的单向链表,在节点的数据域中放入了具有两个字符的字符串。函数disp的功能是显示输出该单链表中所有节点中的字符串。请填空完成函数disp。
#include<stdio.h>
typedef struct node/*链表节点结构*/
char sub[3];
struct node*next;
Node;
Node fun(char s)/*建立链表*/
…
void disp(Node*h)
Node*p;
p=h->next;
while______
printf("%s\n",p->sub);
p=p->next;
main()
Node*hd;
hd=fun();
disp(hd);
printf("\n");
答案
参考答案:p!=NULL
解析: 函数fun()的功能为建立链表,函数disp()为输出该单链表中所有结点中的字符串,while语句需判断指针是否已指向单向链表的结尾,即为关系运算表达式p!=NULL。