华师大数据结构期中考试试卷(含答案)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

}
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 pointer 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_half;
if ((midpoint = sub_list) == NULL) return NULL; // List is empty.
// pushes the contents of the given stack onto this stack;
3. (10 分) Write the following function temple:
}
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,
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:"<<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); }
2. A list 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) list
3. 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 << 1; Quiz(n - 1); } }
3. Read the following program and fill the blank to complete the method. template <class Node_entry> struct Node { // data members Node_entry entry; Node<Node_entry> *next; Node<Node_entry> *back; // constructors Node( ); Node(Node_entry item, Node<Node_entry> *link_back = Node<Node_entry> *link_next = NULL); }; template <class List_entry> void List<List_entry> :: set_position(int position) const /* Pre: position is a valid position in the List : 0 <=position < count . Post: The current Node pointer references the Node at position . */ {
}
}
second_half = 【11】
;
midpoint->next = NULL;
return second_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.

二三四

六七
八 总分 阅卷人签名
一、 单项选择题(共 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 out b) First in and last out c) First in and first out
target , then position locates one such entry, and a code of succe百度文库s is
returned. Otherwise, not_present is returned, and position is undefined.
Uses: recursive_binary_2, together with methods from the classes Ordered_list
二、 填空题(共 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 ) {
what is the value of the expression Func(12, 15) ? a) 81 b) 62 c) 19 d) 72 e) none of the above
6. Shell sort finally perform an ordinary ( )? a) Heap sort b) Insertion sort c) Selection sort d) Quick sort
Tim Dot Eva Roy Tom Kim Guy Amy Jon Ann Jim Kay Ron Jan
2. (16 分) Write the following overload operator for stacks:
1) bool Stack::operator == (const Stack & s); 2) bool Stack::operator += (const Stack & s);
华东师范大学期中试卷 2007—2008 学年第二学期
课程名称:______数据结构_____ 姓 名:___________________ 专 业:___________________ 课程性质:专业必修
学 号:__________________ 年级/班级:__________________
return recursive_binary_2(the_list, target, 【7】 , top, position);
else
return recursive_binary_2(the_list, target, bottom, 【8】 , position);
}
else return not_present;
int bottom, int top, int &position)
/* Pre: The indices bottom to top define the range in the list to search for the
target .
Post: If a Record in the range from bottom to top in the list has key equal to
a)
00011011
b)
11100100
c)
10011100
d)
01100011
e)
001101
4. 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) 2i b) 2i-1 c) 2i-2 d) 2i+1
5. 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); }
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)
if (n > 0) {
Func(n / 8); cout << n % 8; } }
2. Give the output of the following program. ________【2】__________. template <class List_entry> void print(List_entry &x){
NULL,
if (current_position <= position)
for ( ; current_position != position; current_position++)
【3】
;
else
for ( ; current_position != position;
【4】
)
current = current->back;
position = midpoint->next;
while ( 【9】 ) {
// Move position twice for midpoint's one move.
position = position->next;
if (position != NULL) {
【10】
;
position = position->next;
相关文档
最新文档