C高级程序应用题库
时间:2010-07-26
来源:互联网
1. 以下程序建立了一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1表示输入结束(链表头结点的data 域不放数据,表空的条件是ph->next = = NULL).
#include <stdio.h>
#include <malloc.h>
struct list
{
int data;struct list *next;
};
【1】 creatlist()
{
struct list *p,*q,*ph;
int a;
ph=(struct list *) malloc(sizeof(struct list));
p=q=ph;
printf("Input an integer number,enter -1 to end:\n");
scanf("%d",&a):
while(a!=-1)
{
p=(struct list *)malloc(sizeof(struct list));
p->data=a; q->next=p; 【2】 =p;
scanf("%d",&a);
}
p->next='\0';
return(ph);
}
void main()
{
struct list *head;
head=creatlist();
}
答案:【1】struct list * 【2】q
2.下面min3函数的功能是:计算单向循环链表first中每3个相邻结点数据域中值的和,返回其中最小的值。请填空。
#include <stdio.h>
struct node
{
int data;
struct node * link;
};
int min3(struct node * first)
{
struct node *p=first;
int m,m3=p->data+p->link->data+p->link->link->data;
for(p=p->link; p! =first; p= 【1】 )
{
m=p->data+p->link->data+p->link->link->data;
if( 【2】 )
m3=m;
}
return(m3);
}
答案:【1】p->link 【2】mm或m<=m3或m3>=m
3. 以下函数creat用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾。单向链表的头指针作为函数值返回.请填空:
#include <stdio.h>
#include <malloc.h>
struct list {
char data;
struct list * next;
};
struct list * creat()
{
struct list * h,* p,* q;
char ch;
h= 【1】 malloc(sizeof(struct list));
p=q=h;
ch=getchar();
while(ch!='?')
{
p= 【2】 malloc(sizeof(struct list));
p->data=ch;
p->next=p;
q=p;
ch=getchar();
}
p->next='\0';
【3】
}
答案:【1】(struct list *) 【2】(struct list *) 【3】return(h); 或 return h; ;
#include <stdio.h>
#include <malloc.h>
struct list
{
int data;struct list *next;
};
【1】 creatlist()
{
struct list *p,*q,*ph;
int a;
ph=(struct list *) malloc(sizeof(struct list));
p=q=ph;
printf("Input an integer number,enter -1 to end:\n");
scanf("%d",&a):
while(a!=-1)
{
p=(struct list *)malloc(sizeof(struct list));
p->data=a; q->next=p; 【2】 =p;
scanf("%d",&a);
}
p->next='\0';
return(ph);
}
void main()
{
struct list *head;
head=creatlist();
}
答案:【1】struct list * 【2】q
2.下面min3函数的功能是:计算单向循环链表first中每3个相邻结点数据域中值的和,返回其中最小的值。请填空。
#include <stdio.h>
struct node
{
int data;
struct node * link;
};
int min3(struct node * first)
{
struct node *p=first;
int m,m3=p->data+p->link->data+p->link->link->data;
for(p=p->link; p! =first; p= 【1】 )
{
m=p->data+p->link->data+p->link->link->data;
if( 【2】 )
m3=m;
}
return(m3);
}
答案:【1】p->link 【2】mm或m<=m3或m3>=m
3. 以下函数creat用来建立一个带头结点的单向链表,新产生的结点总是插在链表的末尾。单向链表的头指针作为函数值返回.请填空:
#include <stdio.h>
#include <malloc.h>
struct list {
char data;
struct list * next;
};
struct list * creat()
{
struct list * h,* p,* q;
char ch;
h= 【1】 malloc(sizeof(struct list));
p=q=h;
ch=getchar();
while(ch!='?')
{
p= 【2】 malloc(sizeof(struct list));
p->data=ch;
p->next=p;
q=p;
ch=getchar();
}
p->next='\0';
【3】
}
答案:【1】(struct list *) 【2】(struct list *) 【3】return(h); 或 return h; ;
作者: liuyulan1018 发布时间: 2010-07-26
看起来还不错,mark一下。

作者: ChiyuT 发布时间: 2010-07-26
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28