首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
针对以下C语言程序,请按要求回答问题。 已知link. c源程序如下: /*link. c程序对单向链表进行操作,首先建立一个单向链表,然后根据用户的选择可以对其进行插入结点、删除结点和链表反转操作*/ #include<stdio. h
针对以下C语言程序,请按要求回答问题。 已知link. c源程序如下: /*link. c程序对单向链表进行操作,首先建立一个单向链表,然后根据用户的选择可以对其进行插入结点、删除结点和链表反转操作*/ #include<stdio. h
admin
2013-03-13
98
问题
针对以下C语言程序,请按要求回答问题。
已知link. c源程序如下:
/*link. c程序对单向链表进行操作,首先建立一个单向链表,然后根据用户的选择可以对其进行插入结点、删除结点和链表反转操作*/
#include<stdio. h>
#include<stdlib. h>
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 * p_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:\n");
//建立一个单向链表
prt=create(); //ptr指向链表的第一个结点
print(ptr);
//根据用户的不同选择进行相应的操作:
printf("input number 0,you can quit the program\n");
printf("input number 1,you can insert a new node to link\n"):
printf("input number 2,you can delete a node from the link\n");
printf("input number 3,you can invert the link\n"):
printf("please input you choice\n");
scanf("%d",&choose);
while(choose!=0){
switch(choose){
case 1:
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\n");
printf("please input the location of the node:\n");
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\n");
ptr=invert(ptr);
print(ptr);
break;
default;
break;
return -1;
}
printf("please input you choice\n");
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:\n");
scanf("%d". &length):
printf("the number of the link is:%d",length);
printf("please input the data for the link node:\n");
i=0;
p1=p2=(list_pointer)malloc(sizeof(list_node));
head=p1;
for(i=1;i<length;i++){
scanf("%d",&current);
p1->data=current;
p2->link=p1;
p2=p1;
p1=(list_pointer)malloc(sizeof(list_node));
}
p2->link=NULL;
return head;
}
画出主函数main的控制流程图。
选项
答案
主函数的控制流程如下图所示。 [*]
解析
转载请注明原文地址:https://www.kaotiyun.com/show/saNZ777K
本试题收录于:
四级软件测试工程师题库NCRE全国计算机四级分类
0
四级软件测试工程师
NCRE全国计算机四级
相关试题推荐
网络传输介质包括有线介质与无线介质,但(61)目前还不是网络传输介质。网络的数据传输速率通常采用单位bps,它代表(62)。
在虚拟页式存储管理中,缺页中断属于(13),其功能不包括(14)。
与递归技术的联系最弱的是(42)算法策略。
对于二维数组A[0..5,1..8],设每个元素占1个存储单元,且以列为主序存储,则元素A[3,6]相对于数组空间起始地址的偏移量是(40)。
若有一个仓库,可以存放P1、P2:两种产品,但是每次只能存放一种产品,要求:①w=P1的数量-P2的数量②-i<w<k(i、k为正整数)若用PV操作实现P1和P2产品的入库过程,至少需要(51)同步信号量及(52)个互斥信号量,其中,同步
软件开发的螺旋模型综合了瀑布模型和演化模型的优点,还增加了(6)。采用螺旋模型时,软件开发沿着螺线自内向外旋转,每转一圈都要对(7)进行识别和分析,并采取相应的对策。螺旋线第一圈的开始点可能是一个(8)。从第二圈开始,一个新产品开发项目开始了,新产品的演化
结构化分析过程中,一般认为首先应该考虑的问题应是进行(29)。
某系统总线的一个总线周期包含3个时钟周期,每个总线周期中可以传送32位数据。若总线的时钟频率为33MHz,则总线带宽为(18)。
数据结构是—门研究非数值计算的程序设计问题中计算机的(34)以及它们之间的(35)和运算等的学科。
信息安全就是要防止非法攻击和病毒的传播,保障电子信息的有效性,从具体的意义上来理解,需要保证哪几个方面的内容?(40)。 Ⅰ.保密性(Confidentility)Ⅱ.完整性(InteSdty)Ⅲ.可用性(Availability)Ⅳ.可控性
随机试题
X线摄影方向不包括
用于组成冬眠合剂的药物有
在发生不对称短路的网络中,下列说法中不正确的是()。
在正常施工条件下生产工人进行施工作业的定额时间包括()。
宏观经济政策的目标有()。
2018年8月8日,某县工商部门查获一起假冒服装销售行为,甲公司销售多种假冒名牌服装。为防止甲公司逃避处罚,执法人员要求甲公司当场缴纳2000元罚款。之后,执法人员告知甲公司,如果对处罚结果不服,可以向工商部门提出听证申请。根据上述资料,为下列问题从备
北宋“熙宁兴学”强调实用人才的培养,在教学内容方面的改革是编写和颁布《三经经义》,所谓三经,包含《诗》《书》和()。
Whichcountriessponsoredthemeasure?
A、Themovieisnotgood.B、Themovieisexcellent.C、Hewantstoseethemovieagain.D、Hedoesn’twanttostayhome.A本题根据四个选项,
Waffles?Frenchtoast?Bacon?Bigbreakfastsmaybeathingofthepast.AccordingtotheAssociatedPress,moreAmericansarec
最新回复
(
0
)