• Sonuç bulunamadı

2. 1. 100 Minutes Ömer ÇAKIR COM 2005 Data Structures Resit Exam, 27.01.2017, 15:00, D-1 Duration : Karadeniz Technical University Department of Computer Engineering Lecturer

N/A
N/A
Protected

Academic year: 2021

Share "2. 1. 100 Minutes Ömer ÇAKIR COM 2005 Data Structures Resit Exam, 27.01.2017, 15:00, D-1 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 Resit Exam, 27.01.2017, 15:00, D-1

Duration : 100 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 traverse1(Node* v) {

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

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

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

}

void traverse2(Node* v) {

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

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

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

}

void traverse3(Node* v) {

if (v->left == NULL) cout << v->elt << " ";

else traverse3(v->left);

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

}

void traverse4(Node* v) {

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

if (v->right == NULL) cout << v->elt << " ";

else traverse4(v->right);

}

1.

What is the outputs of the functions above that are called in the main() with the root of the tree below?

(20P)

8 4

2 6

3 5 7

12

10 14

9 11 13 15 1

traverse1:

traverse2:

traverse3:

traverse4:

void traverse(Node* v) {

stack<Node*> stl_stack;

Node* current = v;

while (true) {

if (current != NULL) {

stl_stack.push(current);

current = current->left;

} else {

if (stl_stack.empty()) {

return;

} else {

current = stl_stack.top();

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

stl_stack.pop();

current = current->right;

} }

} }

2.

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

(2)

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

if(head == NULL) {

cout << "List is empty !" << endl; return;

}

if ((strcmp((char*)&head->elem, (char*)&e)) && (head->score == i)) {

SinglyNode* temp = head;

head = head->next;

delete temp;

return;

}

SinglyNode* current = head;

while (current->next != NULL) {

if ((strcmp((char*)&current->next->elem,(char*)&e)) && (current->next->score == i)) {

...

...

...

return;

}

current = current->next;

}

if (current->next == NULL)

cout << "\n" << e << " is not found" << endl;

}

3.

Complete the removeOrdered() function. (25P) Hint  current->next is the node to be deleted.

Zig (X:Sol)

4

7 8 6

1 3

Zig-Zig (X:Sağ, P:Sağ) Zig-Zig (X:Sol, P:Sol)

Zig (X:Sol)

Zig-Zig (X:Sağ, P:Sağ) Zig-Zag (X:Sol, P:Sağ) Zig-Zag (X:Sağ, P:Sol) Zig-Zag (X:Sağ, P:Sol)

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