试题与答案

针对以下C语言程序,请按要求回答问题。 已知link. c源程序如下: /*link

题型:问答题

题目:

针对以下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 linkkn");
printf("input number 3, you can invert the link\n");
printf("please input you choicekn");
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", ¤t);
p1->data=current;
p2->link=p1;
p2=p1;
p1=(list_pointer)malloc(sizeof(list_node));
}
p2->link=NULL;
return head;
}

画出主函数main的控制流程图。

答案:

参考答案:

解析:主函数的控制流程如下图所示。

试题推荐
题型:问答题

请在“答题”菜单中选择“字处理”命令,然后按照题目要求打开相应的命令,完成下面的内容,具体要求如下:
[文档开始]
2010年人民币汇率如何走
如果用一句话形容2009年的人民币汇率走势,可以这样概括:对内人民币没有保值,对外没有升值,市场作用基本被排斥,所谓稳定的基础越来越不稳固。当然,其中的原因主要是为了对抗金融危机,因此,其非市场力量的太多使用也是暂时的“非常手段”。2010年不可持续。
2010年的人民币汇率怎么走关心的人越来越多,分歧也越来越大。撇开外界“压力”不说,国内经济学界、企业界已经越来越多地对所谓固定汇率、捆绑汇率提出质疑——许多经济学家、银行家、企业家都在呼吁人民币汇率逐步实现自由浮动,并将目前经济过热、资产价格虚涨、通货膨胀预期抬头等“祸水”泼向了人民币汇率过于僵硬的不浮动制度。
预计2010年人民币汇率兑美元的升值幅度在3%~5%之间,而对欧元、日元、英镑的升值幅度将远远超过对美元的升值幅度。因为美元在2010年上半年会维持强势。
2010年2月24日人民币外汇牌价
交易币种 交易单位 基准价 卖出价 现汇买入价 现钞买入价
英镑 100 1058.32 1058.67 1050.241017.81
港币 10087.94 88.1187.78 87.07
美元 100682.7 684.02681.28 675.82
瑞士法郎 100 634.05629 609.58
新加坡元 100 486.43482.55 467.66
瑞典克朗 100 94.9494.19 91.28
丹麦克朗 100 124.9123.91 120.08
挪威克朗 100 115.85114.93 111.38
[文档结束]
对考生文件夹下WORD.DOC文档中的文字进行编辑、排版和保存,具体要求如下:

将标题段文字设置为二号阴影黑体、加粗倾斜、居中并加浅绿色底纹。

查看答案
微信公众账号搜索答案