题目详情
当前位置:首页 > 计算机考试 > 初级程序员
题目详情:
发布时间:2023-12-20 20:27:54

[单项选择]与单向链表相比,双向链表()
A. 需要较少的存储空间
B. 遍历元素需要的时间较短
C. 较易于访问相邻结点
D. 较易于插入和删除元素

更多"与单向链表相比,双向链表()"的相关试题:

[单项选择]与单向链表相比,双向链表()
A. 需要较少的存储空间
B. 遍历元素需要的时间较短
C. 较易于访问相邻结点
D. 较易于插入和删除元素
[填空题]下面程序中函数creat用于建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾,单向链表的头指针作为函数值返回。将程序补充完整。
#include<stdiao.h>
struct list
char data; struct list * next;;
struct list * creat( )

struct list *h,*p,*q; char ch;
h= 【18】 malloc(sizeof(struct list));
p=q=h;ch=getchar( );
while(ch!=’’)

p= 【19】 malloc(sizeof(struct list));
p->data=ch;q->next=p;q=p;ch=getchar( );

p->next=’/0’;
【20】

[填空题]以下函数creat用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾。单向链表的头指针作为函数值返回。请填空。 #include <stdio.h> struct list { char dara; struct list *next; }; struct list *creat( ) { struct list *h,*p,*q; char ch; h= (struct list (*) malloc (sizeof (struct list)); ______; ch=getchar( ); while(ch!=’’) { p=(struct list*) malloc) sizeof (struct list)); p->data=ch; ______; q=p; ch=getchar( ); } p->next=’/0’; ______: }
[填空题]以下函数creat用来建立一个带头结点的单向链表,新产生的结点是插在链表头的
末尾。单向链表的头指针作为函数值返回。请填空。
# include<stdio.h>
struct list
char data;
struct list * next;

struct list * creat;
struct list * h,* p,* q;
char ch;
h=(______)malloc ( sizeof(struct list));
p=q=h;
ch=getchar( );
while(ch!=’’)
p=(______)mallco(sizeof(struct list));
p->data=ch;
q->next=p;
q=p;
ch=getchar( );

p->next=’/0’;
______;

[填空题]已知h1和h2为两个单向链表的头指针,h1指向的链表不为空链表。add函数的功能是将h2指向的链表(简称h2链表)中全部结点插入到h1指向的链表(简称h1链表)中第n个结点(n>0)之后,如果h2链表为空链表,则函数直接返回h1链表首结点的地址。如果h1链表中不存在第n个结点,则将h2链表中全部结点添加到h1链表的末尾,函数返回h1链表首结点地址.链表结点采用如下形式的数据结构: struct node { int data; struct node *next; }; #include struct node *add(struct node *h1,struct node *h2,int n) {struct node *p1=h1,*q=h2,*p2; int i=0; if(h2==___(27)___) return h1; p2=h1; while(p1&&inext; ___(28)___; } if(inext=q; else { ___(29)___=q; while(q->next) q=q->next; q->next=___(30)___; } return h1; }
[简答题]已知一个单向链表结点的数据结构定义如下: struct node { char data; struct node *next; }; 函数struct node *cre (char *s)的功能是:根据s指向的字符串建立一个结点类型为struct node头指针为h的单向链表,使h链表中各结点的数据域分别存储s指向字符串中所有大写字母的编码,函数返回h链表首结点的地址.例如,若s指向的字符串为"3Aa26Bx5Y9",则h指向的链表如下图所示。 #include #include struct node { char data; struct node *next; }; struct node *cre(char *s) { struct node *p,*p1,*h; if (___(27)___) return NULL; h=p1=p=(struct node *)malloc(sizeof(struct node)) ; p->data=*s ; s++; while (*s) { if(*s>=’A’ && *s<=’Z’) { p= (struct node *) malloc (sizeof (struct node)) ; p->data=*s ; ___(28)____ = p; p1=p ; } s++; } ___ (29)___ =NULL; ___(30)___; } void print(struct node *h) { struct node *p=h; while (p!=NULL) { printf ("%3c", p->d
[填空题]已知bead指向一个带头结点的单向链表,链表中每个结点包含数据域(data)和指针域(next),数据域为整型。以下函数求出链表中所有连接点数据域的和值作为函数值返回。请在横线处填入正确内容。
int data; struct link *next;
main( )
struct link *head;
sam(______);
stmct link *p;int s=0;
p=head->next;
while(p)s+=p->data;p=p->next;
return(s);
[填空题]以下程序建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-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 list));
p=q=ph;printf("Input an integer number;entre-1 to end:/n");
scanf("%d",&a);
while(a!=-1)
p=(struct list*)malloc(sizeof(struct list));
【19】 =a;q->next=p; 【20】 =p;scanf("%d",&a);
p->next=’/0’;return(ph);
main( )
struct list * head;head=creatlist( );
[填空题]以下程序的功能是建立—个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-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 list)); p=q=ph;printf("Input an integer number;entre-1 to end:/n"); scanf("%d",&a); while(a!=-1) { p=(struct list*)malloc(sizeof(struct list)); [14] =a;q->next=p; [15] =p;scanf("%d",&a);} p->next=’/0’;return(ph);} main( ) {stuct list * head;head=creatlist( );}
[填空题]在给定程序中,函数fun的功能是:将不带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构。
文件BLANK1.C内容如下:
#include<stdio.h>
#include<stdlib.h>
#define N 5
typedef struct node
int data;
struct node *next;
NODE;
/**********found**********/
(1) fun(NODE *h)

NODE *p,*q,*r;
p=h;
if(p==NULL)return NULL;
q=p->next:
p->next=NULL;
/**********found**********/
while( (2) )
r=q->next;
q->next=p;
p=q;
/**********found**********/
q= (3)

return p;

NODE *creatlist(int a[]) NODEh,*p,*q;
int i;
h=NULL;
for(i=0;i<N;i++)
q=(NODE%)malloc(sizeof(NODE));
q->data=a[i];
q->next=NULL;
if(h==NULL)h=p=q;
else p->next=q;p=q;

return h;

void outlist(NODE *h)
NODE *p;
p=h;
if(p==NULL)prin
[填空题]请补充fun函数,该函数的功能是:将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
#include <stdio.h>
#include <stdlib.h>
#define N 5
typedef Struct node
int data;
struct node *next;
NODE;
void fun(NODE *h)

NODE *p, *q, *r;
p= (1) ;
if ( (2) ) return;
q=P->next;
P->next=NULL;
while (q)

r=q->next;
q->next=p;
p=q;
q= (3) ;

h->next=p;

NODE *creatlis (int a[])

NODE *h, *p, *q; int i;
h= (NODE *)malloc(sizeof(NODE));
h>next=NULL:
for(i=0; i<N; i++)

q=(NODE *)malloc(sizeof(NODE));
q->data=a[i];
q->next=NULL;
if(h->next==NULL)
h->next=p=q;
else

p->next=q; p=q;


return h;

void ou list(NODE *h)

NODE *p;
p=h->next;
if(p==NU
[简答题]给定程序中,函数fun的功能是将不带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include #include #define N 6 typedef struct node { int data; struct node *next; } NODE; void fun(NODE *h) { NODE *p, *q; int t; p = h; while (p) { q = __1__ ; while (__2__) { if (p->data > q->data) { t = p->data; p->data = q->data; q->data = t; } q = q->next; } p = __3__ ; } } NODE *creatlist(int a[]) { NODE *h,*p,*q; int i; h=NULL; for(i=0; idata=a[i]; q->next = NULL; if (h == NULL) h = p = q; else { p->next = q; p = q; } } return h; } void outlist(NODE *h) { NODE *p; p=h; if (p==NULL) printf("The list is NULL!/n"); else { printf("/nHead "); do { printf("->%d", p->data); p=p->next; } while(p!=NULL); printf("->End/n"); } } main( ) {

我来回答:

购买搜题卡查看答案
[会员特权] 开通VIP, 查看 全部题目答案
[会员特权] 享免全部广告特权
推荐91天
¥36.8
¥80元
31天
¥20.8
¥40元
365天
¥88.8
¥188元
请选择支付方式
  • 微信支付
  • 支付宝支付
点击支付即表示同意并接受了《购买须知》
立即支付 系统将自动为您注册账号
请使用微信扫码支付

订单号:

请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码