2015年广工数据结构Anyview答案.doc

上传人:re****.1 文档编号:562049027 上传时间:2022-11-25 格式:DOC 页数:51 大小:204.50KB
返回 下载 相关 举报
2015年广工数据结构Anyview答案.doc_第1页
第1页 / 共51页
2015年广工数据结构Anyview答案.doc_第2页
第2页 / 共51页
2015年广工数据结构Anyview答案.doc_第3页
第3页 / 共51页
2015年广工数据结构Anyview答案.doc_第4页
第4页 / 共51页
2015年广工数据结构Anyview答案.doc_第5页
第5页 / 共51页
点击查看更多>>
资源描述

《2015年广工数据结构Anyview答案.doc》由会员分享,可在线阅读,更多相关《2015年广工数据结构Anyview答案.doc(51页珍藏版)》请在金锄头文库上搜索。

1、2015年广工数据结构Anyview答案/*1.06【题目】试写一算法,实现顺序栈的判空操作StackEmpty_Sq(SqStack S)。顺序栈的类型定义为:typedef struct ElemType *elem; / 存储空间的基址 int top; / 栈顶元素的下一个位置,简称栈顶位标 int size; / 当前分配的存储容量 int increment; / 扩容时,增加的存储容量 SqStack; / 顺序栈*/Status StackEmpty_Sq(SqStack S)/* 对顺序栈S判空。 */ /* 若S是空栈,则返回TRUE;否则返回FALSE */ if(S.t

2、op = 0) return TRUE; else return FALSE;/*1.08【题目】试编写算法求一元多项式 P(x) = a0 + a1x + a2x2 + . + anxn的值P(x0),并确定算法中每一语句的执行次数和整个算法的时间复杂度。*/float Polynomial(int n, int a, float x)/* 求一元多项式的值P(x)。 */* 数组a的元素ai为i次项的系数,i=0,.,n */ float jieguo=an; /1次 for(int i=n-1;i=0;i-) /n次 jieguo=ai+x*jieguo; return jieguo;

3、/整体时间复杂度T(n)=O(n) /*1.11【题目】已知k阶裴波那契序列的定义为 f(0)=0, f(1)=0, ., f(k-2)=0, f(k-1)=1; f(n)=f(n-1)+f(n-2)+.+f(n-k), n=k,k+1,.试编写求k阶裴波那契序列的第m项值的函数算法,k和m均以值调用的形式在函数参数表中出现。*/Status Fibonacci(int k, int m, int &f) /* 求k阶斐波那契序列的第m项的值f */ if(m0) return ERROR; if(m=2&m=k) int Temp100; for(int j =k;j1;j-) Tempk-

4、j=0; Tempk-1=1; for(int i=0;(k+i)=m;i+) int temp=0; for(int s=1;sMAXINT时,应按出错处理。注意选择你认为较好的出错处理方法。*/Status Series(int a, int n) /* 求i!*2i序列的值并依次存入长度为n的数组a; */* 若所有值均不超过MAXINT,则返回OK,否则OVERFLOW */ long m=1; for(int i=1;i=n;i+) m=m*i*2; if(m=MAXINT) ai-1=m; else return OVERFLOW; return OK;/*1.23【题目】假设有A

5、、B、C、D、E五个高等院校进行田径对抗赛,各院校的单项成绩均以存入计算机并构成一张表,表中每一行的形式为: 项目名称 性别 校名 成绩 得分编写算法,处理上述表格,以统计各院校的男、女总分和团体总分,并输出。*/void Scores(ResultType *result, ScoreType *score)/* 求各校的男、女总分和团体总分, 并依次存入数组score */* 假设比赛结果已经储存在result 数组中, */* 并以特殊记录 , male, , , 0 (域scorce=0)*/* 表示结束 */ int i=0;while(resulti.sport!=NULL) sw

6、itch(resulti.schoolname)case A:score 0 .totalscore+=resulti.score;if(resulti.gender=male) score 0 .malescore+=resulti.score;else score 0 .femalescore+=resulti.score;break;case B:score 1 .totalscore+=resulti.score;if(resulti.gender=male) score1 .malescore+=resulti.score;else score 1 .femalescore+=res

7、ulti.score;break;case C:score 2.totalscore+=resulti.score;if(resulti.gender=male) score 2 .malescore+=resulti.score;else score 2 .femalescore+=resulti.score;break;case D:score 3 .totalscore+=resulti.score;if(resulti.gender=male) score 3 .malescore+=resulti.score;else score 3 .femalescore+=resulti.sc

8、ore;break;case E:score 4.totalscore+=resulti.score;if(resulti.gender=male)score 4 .malescore+=resulti.score;else score 4 .femalescore+=resulti.score;break;i+;for(i=0;i5;i+)printf(the school %s: , resulti.schoolname) ; printf(Total score of male:%dn,scorei.malescore);printf(Total score of female:%dn,

9、scorei.femalescore);printf(Total score of all:%dnn,scorei.totalscore);/*2.06【题目】试写一算法,对序列S的第i个元素赋以值e。序列的类型定义为:typedef struct ElemType *elem; int length; Sequence;*/Status Assign(Sequence &S, int i, ElemType e) /* 对序列S的第i个元素赋以值e,并返回OK。 */* 若S或i不合法,则赋值失败,返回ERROR */ for(int j;jS.length) return ERROR; S

10、.elemi = e; return OK;/*2.09【题目】试写一算法,由长度为n的一维数组a构建一个序列S。序列的类型定义为:typedef struct ElemType *elem; int length; Sequence;*/Status CreateSequence(Sequence &S, int n, ElemType *a) /* 由长度为n的一维数组a构建一个序列S,并返回OK。 */* 若构建失败,则返回ERROR */ if(n=0) return ERROR; S.elem=(ElemType *)malloc(n*sizeof(ElemType); S.elem=a; S.length=n; return OK;/*2.21【题目】链表的结点和指针类型定义如下 typedef struct LNode ElemType data; struct LNode *next; LNode, *LinkList;试写一函数,构建一个值为x的结点。*/LinkList MakeNode(ElemType x)/* 构建一个值为x的结点,并返回其指针。*/* 若构建失败,则返回NULL。 */ LNode new; new.data=x;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号