版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.华东师范大学期中试卷20072008学年第二学期课程名称:_数据结构_ 姓 名:_ 学 号:_专 业:_ 年级/班级:_课程性质:专业必修一二三四五六七八总分阅卷人签名一、 单项选择题(共18分,每题3分)1. Stack has the property called last in and first out, then which of the following describes the property of Queue?a) Last in and first outb) First in and last outc) First in and first out2. A li
2、st of items from which only the item most recently added can be removed is known as a ( )a) stack b) queue c) circular linked list d) list3. If the following function is called with a value of 2 for n, what is the resulting output? void Quiz( int n ) if (n > 0) cout << 0; Quiz(n - 1); cout
3、<< 1; Quiz(n - 1); a)00011011 b)11100100 c)10011100 d)01100011 e)0011014. A heap is a list in which each entry contains a key, and, for all positions i in the list, the key at position i is at lease as large as the keys in positions 2i+2 and ( ), provided these positions exist in the list.a) 2
4、ib) 2i-1c) 2i-2d) 2i+15. Given the recursive function int Func( /* in */ int i, /* in */ int j ) if (i < 11) if (j < 11) return i + j; else return j + Func(i, j - 2); else return i + Func(i - 1, j); what is the value of the expression Func(12, 15) ? a)81 b)62 c)19 d)72 e)none of the above6. Sh
5、ell sort finally perform an ordinary ( )?a) Heap sortb) Insertion sortc) Selection sortd) Quick sort二、 填空题(共22分,每空2分)1. If the following function is called with a value of 75 for n, the resulting output is _【1】_. void Func( /* in */ int n ) if (n > 0) Func(n / 8); cout << n % 8; 2. Give the
6、 output of the following program. _【2】_.template <class List_entry>void print(List_entry &x)cout<<x<<" "void main( )List<int> mylist;for(int i=0;i<5;i+)mylist.insert(i,i);cout<<"Your list have "<<mylist.size()<<" elements:&quo
7、t;<<endl;mylist.remove(0,i);mylist.remove(2,i);mylist.insert(i,i);mylist.traverse(print);mylist.clear( );for(i=1;i<3;i+)mylist.insert(i, i);mylist.traverse(print);3. Read the following program and fill the blank to complete the method.template <class Node_entry>struct Node / data memb
8、ersNode_entry entry;Node<Node_entry> *next;Node<Node_entry> *back;/ constructorsNode( );Node(Node_entry item, Node<Node_entry> *link_back = NULL, Node<Node_entry> *link_next = NULL);template <class List_entry>void List<List_entry> : set_position(int position) cons
9、t/* Pre: position is a valid position in the List : 0 <=position < count .Post: The current Node pointer references the Node at position . */if (current_position <= position)for ( ; current_position != position; current_position+) 【3】 ;elsefor ( ; current_position != position; 【4】 )current
10、= current->back;4. Read the following program and fill the blank to complete the method.Error_code recursive_binary_2(const Ordered_list &the_list, const Key &target, int bottom, int top, int &position)/* Pre: The indices bottom to top define the range in the list to search for the ta
11、rget .Post: If a Record in the range from bottom to top in the list has key equal to target , then position locates one such entry, and a code of success is returned. Otherwise, not_present is returned, and position is undefined.Uses: recursive_binary_2, together with methods from the classes Ordere
12、d_list and Record . */Record data;if (bottom <= top) int mid = 【5】 ;the_list.retrieve (mid, data);if (data = target) 【6】 ;return success;else if (data < target)return recursive_binary_2(the_list, target, 【7】 , top, position);elsereturn recursive_binary_2(the_list, target, bottom, 【8】 , positio
13、n);else return not_present;5. The following program is the divide_from function of Merge Sort. Please fill the blank to complete the function. Node<Record> * divide_from (Node<Record> *sub_list)/* Post: The list of nodes referenced by sub_list has been reduced to its first half, and a po
14、inter to the first node in the second half of the sublist is returned. If the sublist has an odd number of entries, then its first half will be one entry larger than its second.*/Node<Record> *position, / traverses the entire list*midpoint, / moves at half speed of position to midpoint*second_
15、half;if (midpoint = sub_list) = NULL) return NULL; / List is empty.position = midpoint->next;while (【9】 ) / Move position twice for midpoint's one move.position = position->next;if (position != NULL) 【10】 ;position = position->next; second_half = 【11】 ;midpoint->next = NULL;return se
16、cond_half;三、 编程题(共60分)1. (16分)Apply quicksort to the following list of 14 names, where the pivot in each sublist is chosen to be (a) the first key in the sublist and (b) the last key in the sublist. In each case, draw the tree of recursive call.Tim Dot Eva Roy Tom Kim Guy Amy Jon Ann Jim Kay Ron Jan
17、2. (16分)Write the following overload operator for stacks:1) bool Stack:operator = (const Stack & s);2) bool Stack:operator += (const Stack & s);/ pushes the contents of the given stack onto this stack;3. (10分)Write the following function temple:Template <class T> void reverse(Queue <
18、;T> & q);/ reverses the contents of the given queue;4. (18分)struct Node / data membersint entry;Node *next;/ constructorsNode( );Node(int item, Node *link = NULL);f is the head pointer of a link list of nodes.Using recursion, implement the following functions:1) int Max (Node *f ); /return th
19、e max value in the link list.2) int Num (Node *f );/return the number of the nodes in the link list3) Node * Search ( Node *f, int x ); /Search the first occurrence of the x in the link list. If success returns the /pointer to the node, else returns NULL.数据结构期中考卷参考答案.;一、 单项选择题(3×618)1 c2 a3 e4
20、d5 a6 b二、 填空题(2×1122)【1】113【2】Your list have 5 elements:1 2 4 3【3】current = current->next【4】current_position-【5】(bottom + top)/2【6】position = mid【7】mid + 1【8】mid 1【9】position != NULL【10】midpoint = midpoint->next;【11】midpoint->next三、 编程题(16×2101860)1,a) P344 F8.12b)2. 1) bool Stack:operator=(const Stack &s)Stack s1=s, s2=*this;while (!s1.empty( )if (s1.top( )!= s2.top( ) return false;else s1.pop( ); s2.pop( );2) bool Stack: operator+=(const Stack &s)Stack ss=s, s2;wh
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 商业合作利润分成协议
- 信息网络经销商合同
- 商铺转让合同协议书范本
- 高效员工劳动合同模板
- 旅行社转让协议书
- 统编版四年级上册语文9 古诗三首 《暮江吟》 公开课一等奖创新教学设计
- 标准离婚协议书样式示例
- 房屋动拆迁协议书编写指南
- 建筑工程公司项目合作风险评估
- 个人民房买卖合同样本
- (精华)国家开放大学电大专科《网络系统管理与维护》形考任务3答案
- 天网施工标准化
- 2020年四川省德阳市高三一诊考试地理试卷(Word版,含答案)
- 第七章_进出口商品价格
- 小升初学生个人简历模板
- 2022年“短语结构”专题练习及参考答案
- UPI大学生人格问卷ABC等级评定(细则)
- 好转反应原理及处理方式
- ICS国际标准分类号
- 桩基施工台账
- Y3150滚齿机使用说明书
评论
0/150
提交评论