更多"给定程序MODI1.C是建立一个带头结点的单向链表, 并用随机函数为各"的相关试题:
[填空题]下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数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;
[填空题]下列给定程序中已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数fun的功能是:把形参x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。
请在下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <stdlib.h>
#define N 8
typedef struct list
int data;
struct 1ist * next;
SLIST;
void fun(SLIST * h, int x)
SLIST * P, * q, * s;
s=(SLIST* )malloc(sizeof(SLIST));
/********** found********** /
s->data=______;
q=h;
p=h->next;
while(p! =NULL && x>p->data)
/********** found********** /
q=______;
p=p->next;
s->next=p;
/********** found********** /
q->next=______;
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;
voi
[简答题]下列给定程序中,已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数fun的功能是:把形参x的值放入一个新结点并插入链表中,使插入后各结点数据域中的数据仍保持递增有序。
请在下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include <stdio.h>
#include <stdlib .h >
#define N 8
typedef struct list
int data;
struct list * next;
SLIST;
void fun(SLIST * h, int x)
SLIST * p, * q, * s;
s=(SLIST *) malloc (sizeof
(SLIST));
/********** found********** /
s->data= (1) ;
q=h;
p=h->next;
while(p!=NULL && x >p->data)
/********** found********** /
q= (2) ;
p=p->next;
s->next=p;
/********** found********** /
q->next= (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;
[简答题]给定程序中,函数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;
/**********found**********/
p = __1__ ;
while (p) {
/**********found**********/
q = __2__ ;
while (q) {
/**********found**********/
if (p->data __3__ q->data)
{ t = p->data; p->data = q->data; q->data = t; }
q = q->next;
}
p = p->next;
}
}
NODE *creatlist(int a[])
{ NODE *h,*p,*q; int i;
h = (NODE *)malloc(sizeof(NODE));
h->next = NULL;
for(i=0; 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 outlist(NODE *h)
{ NODE *p;
p = h->next;
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( )
{ NODE *head;
int a[N]= {0, 10, 4, 2, 8, 6 };
head=creatlist(a);
printf("/nThe original list:/n");
outlist(head);
fun(head);
printf("/nThe list after sorting :/n");
outlist(head);
}
[填空题]以下程序中函数 fun 的功能是:构成一个如图所示的带头结点的单向链表,在结点 的数据域中放入了具有两个字符的字符串。函数 disp 的功能是显示输出该单向链表 中所有结点中的字符串。请填空完成函数 disp。
head
ab cd ef /0
#include
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");
}
[填空题]以下程序中函数fun的功能是:构成一个如图所示的带头结点的单向链表,在结点的数据域中放入了具有两个字符的字符串。函数disp的功能是显示输出该单链表中所有结点中的字符串。请填空完成函数
disp。
#include
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);prinff("\n");
}
[填空题]给定程序中,函数fun( )的功能是在带有头结点的单向链表中,查找数据域中值为ch的结点。找到后通过函数值返回该结点在链表中所处的顺序号;若不存在值为ch的结点,函数返回0值。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct list
int data;
struct list *next;
SLIST;
SLIST *creatlist(char*);
void outlist(SLIST*);
int fun(SLIST *h,char ch)
SLIST *p;int n=0;
p=h->next;
/**********found**********/
while(p!= (1) )
n++;
/**********found**********/
if(p->data==ch)return (2) ;
else p=p->next;
return 0;
main( )
SLIST *head;int k;char ch;
char a[N]=’m’,’p’,’g’,’a’,’w’,’x’,’r,’d’;
head=creatlist(a);
outlist(head);
printf("Enter a letter:");
scanf("%c",&ch);
/**********found**********/
k=fun( (3) );
if(k==0)printf("/nNot found!/n");
else printf("The sequence number is:%d\n",k);
SLIST *creatlist(char *a)
SLIST*h,*p,*q;int i;
h=
[填空题]请补充函数fun( ),该函数的功能是建立一个带头结点的单向链表并输出到文件“out98.dat”和屏幕上,各结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仪在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio. h>
#include<conio. h>
#include<stdlib. h>
typedef struct ss
int data;
struct ss *next;
NODE;
void fun(int n,char*filename)
NODE *h,*p, *s;
FILE *pf;
int i;
h=p= (NODE *) malloc (sizeof (NODE));
h->data=0;
for (i=1; i
s=(NODE *)malloc (sizeof (NODE));
s->data= 【1】 ;
【2】 ;
p= 【3】
p->next=NULL;
if ( (pf=fopen (filename, "w") ) ==NULL)
printf "Can not open out9B.clat! ");
exit (0);
p=h;
fprintf (pf, "/n***THE LIST***/n");
print f ("/n***THE LIST***/n")
while (p)
fprintf (pf, "%3d", p->data)
printf ("%3d",p->data);
if (p->next ! =NULL)
[简答题]给定程序MODI1.C中函数Creatlink的功能是创建带头结点的单向链表,并为各结点数据赋0~m-1的值。
#include<Stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef Struct aa
{ int data;
Struct aa *next;
} NODE;
NODE*Creatlink (int n,int m)
{ NODE *h=NULL,*p,*s;
int i;
/**********found***********/
p=(NODE)malloc (sizeof(NODE));
h=p;
p->next=NULL;
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;
}
/**********found***********/
return p;
}
outlink (NODE *h)
{ NODE *p;
p=h->next;
printf("/n/n THE LIST:/n/n HEAD");
while(p)
{ paintf("->%d",p->data);
p=p->next;
}
printf("/n");
}
main( )
{ NODE *head;
clrscr( );
head=Creatlink(8,22);
outlink(head);
}
[填空题]下列给定程序中,函数fun的功能是:统计带头结点的单向链表中结点的个数,并存放在形参n所指的存储单元中。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#defineN 8
typedef street list
int data;
struct list*next;
SLIST;
SLIST*creatlist(int*a);
void outlist(SLIST*);
void fun(SLIST*h,int*n)
SLIST*p;
/***************found***********/
______=0;
p=h->next;
while(p)
(*n)++;
/*************found***********/
p=p->______;
main( )
SLIST*head;
int a[N]=12,87,45,32,91,16,20,48,num;
head=creatlist(a);
outlist(head);
/*************found*********/
fun(______,&num);
printf("/number=%d/n",num);
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