• Sonuç bulunamadı

2. 1. 120 Minutes Ömer ÇAKIR COM 2005 Data Structures Final Exam, 07.01.2017, 10:00, D-1, D-8 Duration : Karadeniz Technical University Department of Computer Engineering Lecturer

N/A
N/A
Protected

Academic year: 2021

Share "2. 1. 120 Minutes Ömer ÇAKIR COM 2005 Data Structures Final Exam, 07.01.2017, 10:00, D-1, D-8 Duration : Karadeniz Technical University Department of Computer Engineering Lecturer"

Copied!
2
0
0

Yükleniyor.... (view fulltext now)

Tam metin

(1)

Karadeniz Technical University Department of Computer Engineering

Lecturer Ömer ÇAKIR

COM 2005 Data Structures Final Exam, 07.01.2017, 10:00, D-1, D-8

Duration : 120 Minutes

NUMBER : ……… NAME : ………....

SIGNATURE : ………...

EXAM GRADE

[...] ...

Students have to obey Engineering Faculty Exam Execution Instructions.

Brief information about the exam will be given at the begining, then no one is allowed to ask a question during the exam.

void traverse(Node* v) {

if (v->left != NULL) traverse(v->left);

else

if (v->right == NULL)

cout << v->elt << " ";

if (v->right != NULL) traverse(v->right);

}

1.

What is the output of the function traverse() that is called in the main() with the root of the tree below?

(25P)

8 4

2 6

3

5 7

12

10 14

9 11 13 15

1

void traverse(Node* v) {

stack<Node*> stl_stack;

stl_stack.push(v);

while (!stl_stack.empty()) {

Node* current = stl_stack.top();

cout << current->elt << " ";

stl_stack.pop();

if (current->right != NULL)

stl_stack.push(current->right);

if (current->left != NULL)

stl_stack.push(current->left);

} }

2.

What is the output of the function traverse() that is called in the main() with the root of the tree on the left?(25P)

(2)

void insertOrdered(const string& e, const int& i) {

DoublyNode* newNode = new DoublyNode;

newNode->elem = e;

newNode->score = i;

DoublyNode* current = header;

while (current->next != trailer) {

if(newNode->score >= current->next->score) current = current->next;

else break;

}

newNode->next = current->next;

newNode->prev = current;

... = ...;

... = ...;

}

int main() {

DoublyLinkedList list;

list.insertOrdered("Paul", 720);

list.insertOrdered("Rose", 590);

list.insertOrdered("Anna", 660);

list.insertOrdered("Mike", 1105);

list.insertOrdered("Rob" , 750);

list.insertOrdered("Jack", 510);

list.insertOrdered("Jill", 740);

}

3.

Considering the two lines of the insertOrdered() function that are indicated by “...“, which of the following

choises add a node to a doubly linked list erroneously?

(25P) You’ll loose 5P from wrong answer.

(A) newNode->prev->next = newNode;

newNode->next->prev = newNode;

(B) newNode->next->prev = newNode;

newNode->prev->next = newNode;

(C) current->next = newNode;

current->next->next->prev = newNode;

(D) current->next = newNode;

newNode->next->prev = newNode;

(E) current->next = newNode;

current->next->prev = newNode;

Zig (X:Left)

4

3 2

5 6 1 8

Zig-Zig (X:Right, P:Right) Zig-Zag (X:Right, P:Left) Zig (X:Left)

Zig-Zag (X:Right, P:Left) Zig-Zig (X:Left, P:Left) Zig-Zig (X:Right, P:Right) Zig-Zag (X:Right, P:Left)

4.

Find the element insertion order for the Splay Tree above using splay operations in the table. (25P)

Referanslar

Benzer Belgeler

Students have to obey Engineering Faculty Exam Execution Instructions.. Assume that the numbers above are inserted into a

Write words from dictionary.txt to relative.txt using Hash() function to calculate relative addresses and linear probing as a collision resolving method.. In addition,

Write words from dictionary.txt to relative.txt using Hash() function to calculate relative addresses and linear probing as a collision resolving method.. In addition,

Brief information about the exam will be given at the begining, then no one is not allowed to ask a question during the exam?. What is the output of the

Brief information about the exam will be given at the begining, then no one is not allowed to ask a question during the exam.. print2() calls itself

Complete removeOrdered() function above that removes an element from a doubly

insertOrdered() that insert elements with ascending order into a doubly linked list gives an error because line sequence of one or more code block written in bold is changed.. Write

Write the sentences from dictionary.txt to relative.txt like above using Hash() function above.. Use linear probing as a collision