题目详情
当前位置:首页 > 职业培训考试
题目详情:
发布时间:2023-11-22 05:19:17

[填空题]给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用fun函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
#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-> (1) ;

/**********found**********/
printf(”%d”, (2) );
s->next=NULL:
/**********found**********/
free( (3) );

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(

更多"给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用f"的相关试题:

[简答题]

下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数fun( )的功能是:将单向链表结点(不包括头结点)数据域为偶数的值累加起来,并作为函数值返回。
其累加和通过函数值返回main( )函数。例如,若n=5,则应输出8.391667。
请改正程序中的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<stdio.h>
#include<stdiib.h>
typedef struct aa

int data;
struct aa *next;
NODE;
int fun(NODE *h)

int sum=0;
NODE *P;
/**********found**********/
p=h;
while(P->next)

if(p->data%2==0)
sum+=p->data;
/**********found**********/
p=h->next;

return sum;

NODE *creatlink(int n)

NODE *h, *p, *s, *q;
int i, x;
h=p=(NODE *)malloc(si zeof(NODE));
for(i=1; i<=n; i++)

s=(NODE *)malloc(sizeof(NODE));
s->data=rand( )%16;
s->next=p->next;
p->next=s;
p=p->next;

p->next=NULL;
return h;

outlink(NODE *h, FILE *Pf)


[填空题]下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数fun( )的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include <stdio.h> #include <conio.h> #include <stdlib.h> typedef struct aa { int data; struct aa *next; } NODE; /*************found**************/ fun (NODE *h) { int max=-1; NODE *p; p=h->next; while(p) { if(p->data>max) max=p->data; /*************found**************/ p=h->next; } return max; } outresult(int s, FILE *pf) { fprintf(pf, "/nThe max in link :%d/n ",s);} NODE *creatlink(int n, int m) { NODE *h,*p,*s,*q; int i, x; h=p=(NODE *)malloc(sizeof(NODE)); h->data=9999; for(i=1;i<=n;i++) { s=(NODE *) malloc(sizeof(NODE)); s->data=rand( )%m; s->next=p->next; p->next=s; p=p->next; } p->next=NULL; return h; } outlink(NODE *h,FILE *pf) { NODE *p;
[填空题]给定程序MODI1.C是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数fun的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
文件MODI1.C内容如下:
#include<stdio.h>
#include<stdlib.h>
typedef struet aa
int data;
struet aa *next;
NODE;
int fun( NODE *h)
int max=-1:
NODE *p;
/**********found**********/
p=h;
while(p)t
if(p->data>max)max=p->data;
/**********found**********/
p=h->next;

return max;

void outresult(int s,FILE *pf)fprintf(pf,"/nThe max in link: %d/n",s);
NODE *creatlink(int n,int m)
NODE *h,*p,*s;
int i;
h=p=(NODE *)malloc(sizeof(NODE));
h->data=9999;
for(i=1;i<=n;i++)
S=(NODE$)malloe(sizeof(NODE));
s->data=rand( )%m;
s->next=p->next;
p->next=s;
p=p->next;

p->next=NULL;
return h;

void outlink(NODE *h,FILE *pf)
NODE *p;
p=h->next;
fprintf(pf,"/nTHE LIST: /n/n
[简答题]下列给定程序中,是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数fun的作用是求出单向链表结点(不包括头结点)数据域中的最大值,并且作为函数值返回。
请改正程序指定部位的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<stdio.h>
#include<stdlib.h>
typedef struct aa

int data;
struct aa *next;
NODE;
fun(NODE *h)

int max=-1;
NODE *p;
/***********found************/
p=h;
while(p)

if(p->data>max)
max=p->data;
/************found************/
p=h->next;

return max;

outresult(int s, FILE *Pf)

fprintf(pf, "/nThe max in link: %d/n", s);

NODE *creatlink(int n, int m)

NODE *h, *p, *s, *q;
int i, x;
h=p=(NODE *)malloc(sizeof(NODE));
h->data=9999;
for(i=1; i<=n; i++)

s=(NODE *)malloc(sizeof(NODE));
s->data=rand( )%m; s->next=p->next;
p->next=s; p=p->next;

p->next=NULL;
return h;

outlink(NODE *h, FILE *pf)

[填空题]下列给定程序中,函数fun的功能是:统计带头结点的单向链表中结点的个数,并存放在形参n所指的存储单元中。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
int data;
struct list *next;
SLIST;
SLIST *creatlist(int *a);
void outlist(SLIST *);
void fun(SLIST *h, int *n)
SLIST *p;
/******************found*******************/
(1) =0;
p=h->next;
while(p)
(*n)++;
/******************found*******************/
p=p-> (2) ;


main( )
SLIST *head;
int a[N]=12, 87, 45, 32, 91, 16, 20, 48, num;
head=creatlist(a);
outlist(head);
/******************found*******************/
fun( (3) , &num);
printf("/nnumber=%d/n", num);

SLIST *creatlist(int a[])
SLIST *h, *p, *q; int i;
h=p=(SLIST *)malloc(sizeof(SUST));
for(i=0; i<N; i++)
q=
[填空题]在给定程序中,函数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
[填空题]以下程序建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-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( );
[简答题]给定程序中,函数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( ) {
[单项选择]以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转存到链表的各个结点中,请填空。
#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)++

我来回答:

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

订单号:

截图扫码使用小程序[完全免费查看答案]
请不要关闭本页面,支付完成后请点击【支付完成】按钮
恭喜您,购买搜题卡成功
重要提示:请拍照或截图保存账号密码!
我要搜题网官网:https://www.woyaosouti.com
我已记住账号密码