当前位置:网站首页>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;
}边栏推荐
- Window system installation Nacos
- Tutorial details | how to edit and set the navigation function in the coolman system?
- JPA learning 1 - overview, JPA, JPA core annotations, JPA core objects
- Solution of IP network broadcasting system in Middle School Campus - Design Guide for Campus Digital IP broadcasting system
- How does VR panorama make money? Based on the objective analysis of the market from two aspects
- Mirror image of sword finger offer binary tree
- 抖音实战~实现App端视频上传与发布
- 2021-2022 China's financial digitalization "new" insight Industry Research Report
- openGauss内核:简单查询的执行
- Sitelock helps you with the top ten common website security risks
猜你喜欢

JPA学习2 - 核心注解、注解进行增删改查、List查询结果返回类型、一对多、多对一、多对多

2021-2022 China's financial digitalization "new" insight Industry Research Report

Laravel framework knowledge

JPA learning 2 - core annotation, annotation addition, deletion, modification and query, list query result return type, one to many, many to one, many to many

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

UE4 WebBrowser图表不能显示问题

Hello C (I) -- basics of C language

抖音实战~项目关联UniCloud

为什么越来越多的实体商铺用VR全景?优势有哪些?

Using ADC to control brushless motor source program STM32 library function
随机推荐
Is there really something wrong with my behavior?
浅析大型IM即时通讯系统开发难度
In the past 5 years, from "Diandian" to the current test development, my success is worth learning from.
企业级~uni-app网络请求封装
教程详解|在酷雷曼系统中如何编辑设置导览功能?
7-3 maximum sub segment and
Andersen global strengthens the Middle East platform with Palestinian member companies
Hello C (VII) - structure
Investment analysis and prospect forecast report of global and Chinese propargyl chloride industry from 2022 to 2028
ArcGIS加载免费在线历史影像作为底图(不需要插件)
Hello C (V) -- pointer and array
What are the advantages of VR panoramic production? Why is it favored?
Arbitrary file download of file operation vulnerability (7)
Morris traverse
STM32CubeIDE SWV功能使用方法
Andersen Global借助巴勒斯坦成员公司加强中东平台
Today's sleep quality record 79 points
HMS core discovery Episode 13 live broadcast Preview - building the real world in mobile games
技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放
Eye gaze estimation using webcam