当前位置:网站首页>C程序设计专题 18-19年期末考试习题解答(下)
C程序设计专题 18-19年期末考试习题解答(下)
2022-06-24 19:48:00 【雨中春树万人家】
Section 3
注意明确程序目的,需要递归画出图中所示的图形。
(1)MidPoint函数的目的是求出中点并返回,中点坐标以结构类型VERTEX存储。
答案:mAB
(2)这一步的目的是画出当前三个顶点对应的三角形。
答案:DrawTriangle(A,B,C);
(3)(4)(5)当前画出三角形后,还要针对3个子三角形进行递归。
答案:FraTriangle(A,mAB,mCA);
FraTriangle(mAB,B,mBC);
FraTriangle(mCA,mBC,C);
注:保持顶点顺序一致,防止出错。
2.本题目的是:实现循环队列的各项操作。(数组实现,头指针和尾指针用数字(下标)表示)
①对于循环队列,尤其要注意区分队列已满、队列为空的条件。根据题干:"wraps around" to the beginning if the last entry of the buffer is occupied when adding a new entry,可知队列已满的条件是rear和end差一位。
②还要看循环队列能否被塞满。请看CreateQueue函数中的初始化操作,一开始建立的是一个空队列,此时rear和front相等。这说明题中所给循环队列需要一个不存放数据的尾结点。
(6)注意取余数的运算,这一步非常重要,否则可能越界。
答案:Q->front==(Q->rear+1)%(Q->maxsize);
注:所谓队列已满,实际上尾结点仍然不存放数据,如果尾结点也存放数据,则队列满和空两种状态就无法辨别了。
(7)根据CreateQueue函数中的初始化条件,栈空时应该是首尾指针相同。
答案:Q->front==Q->rear;
(8)根据上述分析,我们知道rear对应的结点本身是不存放数据的。
Enqueue函数的实现过程:
若队列已满,则返回。
若队列未满,则首先在旧的尾结点处存放数据,再让尾结点后移。
答案:Q->pBase[Q->rear]=val;
(9)仍需注意节点移动时的取余运算。
答案:(Q->rear+1)%(Q->maxsize);
(10)元素出队列,出队列元素的值是通过指针形式跨函数获取的。
答案:*val
3.本题考查图形库的基本操作。
(11)答案:InitGraphics( );
(12)考查回调函数的相关概念及用法。
答案:KeyboardEventProcess
(13)答案:TimerEventProcess
(14)积累cancelTimer函数的用法。
答案:cancelTimer(TIMER_BLINK100);
(15)切换画圆模式。
答案:isDisplayCircle=!isDisplayCircle
Section 4
1.
思路分析:本题目的是寻找第一个相同的物理结点。根据图示可知:一开始几个结点不同,到第一个共同结点之后,两个链表就相同了。首先确定哪个链表的起始部分结点比较多,得出结点之差n,让结点多的链表先走n个结点,之后两个链表同时走,如此完成遍历即可。
答案:
static ListNode* FindFirstCommonNode(ListNode* l1,ListNode* l2)
{
int len1,len2,numLeftNodes;
ListNode *lPtr,*sPtr;
if(l1==NULL||l2==NULL)
return NULL;
len1=ListLength(l1);
len2=ListLength(l2);
if(len1>len2)
{
lPtr=l1;sPtr=l2;
numLeftNodes=len1-len2;
}
else
{
lPtr=l2;sPtr=l1;
numLeftNodes=len2-len1;
}
for(int i=0;i<numLeftNodes;i++)
lPtr=lPtr->next;
while(lPtr&&sPtr&&lPtr!=sPtr)
{
lPtr=lPtr->next;
sPtr=sPtr->next;
}
return lPtr;
}2.题中涉及二元选择排序,是针对普通选择排序法的一种改进版本。普通选择排序,每一轮只选择一个元素;而二元选择排序每一轮既选出最大元素,又选出最小元素,故遍历次数比普通选择排序减少一半。选择的过程就是选择排序区间从两边向中间一致缩小的过程。
答案:
void binSelection(int array[],int n)
{
int k,tmp,lh,rh,minPos,maxPos;
for(lh=0,rh=n-1;lh<rh;lh++;rh--)
{
minPos=lh;maxPos=rh;
for(k=lh;k<=rh;k++)
{
if(array[minPos]>array[k])
minPos=k;
else if(array[maxPos]<array[k])
maxPos=k;
}
tmp=array[lh];array[lh]=array[minPos];array[minPos]=tmp;
tmp=array[rh];array[rh]=array[maxPos];array[maxPos]=tmp;
}
return;
}边栏推荐
- 7-7 digital triangle
- Scala IO reads binary files
- Development status and prospect trend forecast report of humic acid sodium industry in the world and China from 2022 to 2028
- Leetcode topic [array] -39- combined sum
- 干接点和湿接点
- Analysis report on production and marketing demand and investment forecast of China's boron nitride industry from 2022 to 2028
- 第三代电力电子半导体:SiC MOSFET学习笔记(五)驱动电源调研
- STM32CubeIDE SWV功能使用方法
- China CAE industry investment strategic planning and future development analysis report 2022 ~ 2028
- 都2022年了,你还不了解什么是性能测试?
猜你喜欢

有趣的checkbox计数器

信号完整性(SI)电源完整性(PI)学习笔记(二十五)差分对与差分阻抗(五)

Hydropower project construction scheme based on 3D GIS Development

VR全景怎么赚钱?结合市场从两个方面客观分析下

Canvas spiral style animation JS special effect

DO280OpenShift访问控制--加密和ConfigMap

教程详解|在酷雷曼系统中如何编辑设置导览功能?

Sitelock helps you with the top ten common website security risks

Morris traverse

Arbitrary file download of file operation vulnerability (7)
随机推荐
Window系统安装Nacos
Analysis report on the "fourteenth five year plan" and development trend of China's engineering project management industry from 2022 to 2028
Report on operation pattern and future prospect of global and Chinese propyl isovalerate industry from 2022 to 2028
走近Harvest Moon:Moonbeam DeFi狂欢会
美国众议院议员:数字美元将支持美元作为全球储备货币
Is there really something wrong with my behavior?
Go shopping
使用网络摄像头进行眼睛注视估计
7-9 treasure hunt route
5G dtu无线通信模块的电力应用
Nacos究竟是什么
Fast pace? high pressure? VR panoramic Inn brings you a comfortable life
今天睡眠质量记录79分
ArcGIS加载免费在线历史影像作为底图(不需要插件)
7-2 solving the stock buying problem
Tutorial details | how to edit and set the navigation function in the coolman system?
Hello C (III) - pointer
How does VR panorama make money? Based on the objective analysis of the market from two aspects
Analysis report on operation pattern and supply and demand situation of global and Chinese cyano ketoprofen industry from 2022 to 2028
单调栈以及单调栈的应用