河南分校

您当前位置:公务员考试网 > 河南人事考试网 > 试题汇总 > 公基 > 论述题 3 :针对以下 C 语言程序,请按要求回答问题

论述题 3 :针对以下 C 语言程序,请按要求回答问题( 18 分)已知 l

2020-04-09 12:42:34 河南公务员考试网 //ha.huatu.com/gwy/ 文章来源:华图教育

  【导读】华图河南人事考试网同步华图教育发布:论述题 3 :针对以下 C 语言程序,请按要求回答问题( 18 分)已知 l,详细信息请阅读下文!如有疑问请加【交流群汇总】 ,更多资讯请关注河南华图微信公众号(hnhuatu),微信号:(hnht678) 。

论述题 3 :针对以下 C 语言程序,请按要求回答问题( 18 分)

已知 link.c 源程序如下:

/*link.c 程序对单向链表进行操作 , 首先建立一个单向链表 , 然后根据用户的选择可以对其进行插入节点 、

删除节点和链表反转操作 */

#include

#include

typedef struct list_node *list_pointer; // 定义链表指针

typedef struct list_node{ // 定义链表结构

int data;

list_pointer link;

}list_node;

// 用到的操作函数:

list_pointer create(); // 建立一个单向链表

void insert(list_pointer *p_ptr, list_pointer node); // 在 node 后加入一个新的节点

void delete_node(list_pointer *p_ptr, list_pointer trail, list_pointer node);

// 删除前一个节点是 trail 的当前节点 node

void print(list_pointer ptr); // 打印链表节点中的值

list_pointer invert(list_pointer lead); // 反转链表

int main()

{

list_pointer ptr=NULL;

list_pointer node, trail;

list_pointer *p = &ptr;

int choose, location, i;

printf("you should create a link first: ");

// 建立一个单向链表:

ptr=create(); /* ptr 指向链表的第一个节点 */

print(ptr);

// 根据用户的不同选择进行相应的操作:

printf("input number 0, you can quit the program ");

printf("input number 1, you can insert a new node to link ");

printf("input number 2, you can delete a node from the link ");

printf("input number 3, you can invert the link ");

printf("please input your choice ");

scanf("%d", &choose);

while(choose!=0){

switch(choose){

case 1:

printf("you will insert a node to the link ");

printf("please input the location of the node: ");

scanf("%d", &location);

node = ptr;

i = 1;

while(i<location){

node = node->link;

i++;

}

insert(p, node); /* p 为指向 ptr 的指针 */

print(ptr);

break;

case 2:

printf("you will delete a node from the link ");

printf("please input the location of the node: ");

scanf("%d", &location);

node = ptr;

if(location ==1)

trail = NULL;

trail = ptr;

i = 1;

while(i<location){

trail = trail->link;

i++;

}

node = trail->link;

delete_node(p, trail, node);

print(ptr);

break;

case 3:

printf("you will invert the link ");

ptr = invert(ptr);

print(ptr);

break;

default:

break;

return -1;

}

printf("please input your choice ");

scanf("%d", &choose);

}

return 0;

}

// 根据用户的输入数值建立一个新的单向链表:

list_pointer create()

{

int i, current, length;

list_pointer p1, p2, head;

printf("please input the node number of the link: ");

scanf("%d", &length);

printf("the number of the link is : %d ", length);

printf("please input the data for the link node: ");

i =0;

p1= p2= (list_pointer) malloc(sizeof(list_node));

head = p1;

for(i = 0; i

scanf("%d", ¤ t);

p1->data = current;

p2->link = p1;

p2 = p1;

p1 = (list_pointer) malloc(sizeof(list_node));

}

p2->link = NULL;

return head;

}

……

( 1 )画出主函数 main 的控制流程图。( 10 分)

( 2 ) 设计一组测试用例 , 尽量使 main 函数的语句覆盖率能达到 100% 。 如果认为该函数的语句覆盖率无法达到 100% ,需说明原因。( 8 分)

正确答案:







  以上是论述题 3 :针对以下 C 语言程序,请按要求回答问题( 18 分)已知 l的全部内容,更多关于论述题 3 :针对以下 C 语言程序,请按要求回答问题( 18 分)已知 link.c 源程序如下:快讯信息敬请关注河南人事考试网频道。

试题汇总

本文标签: (编辑:河南华图教育)
有报考疑惑?在线客服随时解惑

公告啥时候出?

报考问题解惑?报考条件?

报考岗位解惑   怎么备考?

冲刺资料领取?

立即咨询
2022年河南教师资格证笔试课程
联系我们
微信二维码

华图教育官方微信

华图总部:北京华图宏阳教育文化发展股份有限公司

联系电话:010-68296100

联系地址:北京市海淀区复兴路甲23号

华图分校:河南华图

郑州黄河路交卫生路向北三叉口东50米路北华图教育培训基地
(红旗路交卫生路东50米路北)

客服热线:0371-87096515

网站://ha.huatu.com

  • 郑州
  • 洛阳
  • 新乡
  • 信阳
  • 南阳
  • 开封
  • 驻马店
  • 三门峡
  • 许昌
  • 安阳
  • 濮阳
  • 平顶山
  • 焦作
  • 商丘
  • 周口
  • 漯河
  • 济源
  • 鹤壁
  • 华图总校

郑州黄河路交卫生路向北三叉口东50米路北华图教育

客服热线:0371-87096515

网站://zhengzhou.huatu.com

洛阳西工区建业凯旋广场东侧商务楼8层

客服热线:0379-62275677

网站://luoyang.huatu.com

新乡市金穗大道星海假日王府华图教育

客服热线:0373-2618333

网站://xinxiang.huatu.com

信阳市解放路与统一街交叉口华图教育

客服热线:0376-6151778

网站://xinyang.huatu.com

南阳市卧龙路工业路交叉口西北角向北100米路西华图教育

客服热线:0377-63192111

网站://nanyang.huatu.com

开封市金明广场北200米路西全季酒店三楼华图教育

客服热线:0371-23157086;0371-22663306

网站://kaifeng.huatu.com

驻马店市文明路与雪松路交叉口一楼门面华图教育

客服热线:0396-3300899

网站://zhumadian.huatu.com

三门峡市建设路与六峰路交叉口向北20米,美居商务酒店院内

客服热线:0398-2182333

网站://sanmenxia.huatu.com

许昌市东城区建安大道与魏文路交叉口东北角华图教育

客服热线:0374-8389007

网站://xuchang.huatu.com

安阳市中华路与德隆街交叉口北50米路东—万达写字楼1307-1311号

客服热线:0372-5956000、5956056

网站://anyang.huatu.com

濮阳市开州中路与政和路交叉口向东濮阳华图

客服热线:0393-5388008、8977110

网站://puyang.huatu.com

平顶山中兴路与和平路步行街交叉口基泰大厦808室

客服热线:0375-6122612

网站://pingdingshan.huatu.com

焦作市山阳区塔南路太极景润(太极广场)焦作华图教育

客服热线:0391-3675776、3885776

网站://jiaozuo.huatu.com

商丘市睢阳区归德路与宇航路交叉口市一高对面往南50米

客服热线:0370-2788345

网站://shangqiu.huatu.com

周口市大庆路北段腾龙名都小区

客服热线:0394-8688160

网站://zhoukou.huatu.com

漯河市交通路与黄河路交叉口(老桥北)兰乔圣菲南门东10米华图教育一楼门面

客服热线:0395-3336991、3291848

网站://luohe.huatu.com

济水大街与文昌路交叉口(鸿运楼)西北角教育书店5楼

客服热线:03922788587

网站://jiyuan.huatu.com

鹤壁淇滨区九州与与步行街西侧交叉口向南50米路西

客服热线:0392-2788587

网站://hebi.huatu.com

地址:北京市海淀区复兴路甲23号

邮编:100036

行政总机:010-68296100

全国热线:4006-01-9999