更多"以下程序建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当"的相关试题:
[填空题]以下程序建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-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));
______=a;q->next=p;______=p;scanf("%d",&a);
p->next=’/0’;return(ph);
main( )
stuct 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的功能是将不带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为: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)++
[单项选择]
以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中,请从与下划线处号码对应的一组选若中选择出正确的选项。#include
stuct node{ char data; struct node *next;}; (1) 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= (2) ;
q->next=p; q= (3) ; s++; }
p->next=’/0’; return h;}main( ){ char str[]="link list";
struct node *head; head=CreatLis(str); ...}
1()
A. char *
B. struct node
C. struct node*
D. char
[填空题]下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点数据域赋值。函数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;
[简答题]
下列给定程序是建立一个带头结点的单向链表,并用随机函数为各结点赋值。函数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)
[单项选择]第48~50题基于以下信息。以下程序的功能是:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中,请从与下划线处号码对应的一组选若中选择出正确的选项。
#include
stuct 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);
...
}
A. char *
B. struct node
C. struct node*
D. char