以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转存到链表的各个结点中,请填空。 #include <stdlib.h> stuct node { char data; struet node * next; }; stntct node * CreatList(char * s) { struet node *h,*p,*q; h = (struct node * ) malloc(sizeof(struct node) ); p=q=h; while( * s! ='\0') { p = (struct node *) malloc ( sizeof(struct node) ); p - > data = ( ) q- >next=p; q=p; a++; p- > next ='\0'; return h; } main( ) { char str[ ]= "link list"; struet node * head; head = CreatList(str);
A.*s
B.s
C.*s++
D.(*s)++
第1题:
以下程序中函数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 *
第2题:
以下程序的功能是建立—个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1时,表示输入结束(链表头结点的data域不放数据,表空的条件是ph->next==NULL),请填空。
include<stdio.h>
struct list { int data;struct list *next;};
struct list * creatlist()
{ struct list *p,*q,*ph;int a;ph=(struct list *)malloc(sizeof(struct
第3题:
以下程序的功能是:建立一个带布头结点的单向链表,并将存储在数组中的字符依次存储到链表的各个结点中,请从与下划线处号码对应的一组选项中选择出正确的选项
#include <stdlib.h>
struct node
{char data; struct node *next;};
(48) CreatList(char*s),
{struct node *h,*p,*q;
h=(struct node*)malloc(sizeof(struct node));
p=q=h;
while(*s!="\0")
{ p=(struct node*)malloc(sizeof(struct node));
p->data= (49) ;
q->next=p;
q= (50) ;
s++;
}
p->next="\0";
return h;
}
main()
{ char str[]="link list";
struct node*head;
head=CreatList(str);
…
}
(1)
A.char*
B.struct node
C.struct node*
D.char
第4题:
以下程序中函数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=[ ];}
}
main()
{ Node *hd;
hd=fun(); disp(hd);printf("\n");
}
第5题:
以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中,请从与下划线处号码对应的一组选若中选择出正确的选项。#include stuct node{ char data; struct node *next;}; (48) CreatLis(char *s){ struct node *h,*p,*q); h=(struct node *)malloc(sizeof(struct node)); p=q=h; while(*s!='\0') { p=(struct node *)malloc(sizeof(struct node)); p->data= (49) ; q->next=p; q= (50) ; s++; } p->next='\0'; return h;}main(){ char str[]="link list"; struct node *head; head=CreatLis(str); ...}
A.char *
B.struct node
C.struct node*
D.char
第6题:
第7题:
以下程序的功能是:建立一个带有头结点的甲—向链表,并将存储在数组中的字符依次转存到链表的各个结点中,请从与下划线处号码对应的一组选项中选择出正确的选项。
#include <stdlib.h>
struct node
{ char data; struct node *next: };
(1) CreatList(char *s)
{
struct node *h,*p,*q;
h = (struct node *)malloc sizeof(struct node));
p=q=h;
while(*s! ='\0')
{
p = (struct node *)malloc(sizeof (struct node));
p->data = (2) ;
q->next = p;
q - (3) ;
S++;
}
p->next='\0';
return h;
}
main()
{
char str[]="link list";
struct node *head;
head = CreatList(str);
}
(1)
A.char*
B.struct node
C.struct node*
D.char
第8题:
● 单向链表中往往含有一个头结点,该结点不存储数据元素,一般令链表的头指针指向该结点,而该结点指针域的值为第一个元素结点的指针。以下关于单链表头结点的叙述中,错误的是 (60) 。
(60)A. 若在头结点中存入链表长度值,则求链表长度运算的时间复杂度为O(1)
B. 在链表的任何一个元素前后进行插入和删除操作可用一致的方式进行处理
C. 加入头结点后,代表链表的头指针不因为链表为空而改变
D. 加入头结点后,在链表中进行查找运算的时间复杂度为O(1)
正确答案:D
试题(60)分析
本题考查数据结构基础知识。
含有头结点的单链表如下图所示
在链表中加入头结点后,查找表中某一元素仍然要从头指针出发,顺序找到目标元素或失败时找到表尾为止,时间复杂度与表长成正比。
第9题:
程序中已构成如下图所示的不带头结点的单向链表结构,指针变量s、P、q、均已正确定义,并用于指向链表结点,指针变量s总是作为头指针指向链表的第一个结点。
该程序段实现的功能是( )。
A.首结点成为尾结点
B.尾结点成为首结点
C.删除首结点
D.删除尾结点
第10题:
在单链表中,增加头结点的目的是( )。
A.方便运算的实现
B.使单链表至少有一个结点
C.标识表结点中首结点的位置
D.说明单链表是线性的链式存储实现