• Sonuç bulunamadı

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

N/A
N/A
Protected

Academic year: 2021

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

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, 02.01.2018, 13:00, D-1

Duration : 90 Minutes

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

SIGNATURE : ………...

EXAM GRADE

[...] ...

Enginnering Faculty Exam Execution Instructions should be obeyed. Questions are related to 1,4,12 of Program Learning Outcomes

void print(DoublyNode* node, bool first) {

if (first)

cout << node->elem << endl;

if (node->next != trailer) print(node->next, false);

else

cout << node->elem << endl;

}

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);

list.print(list.header->next, true);

}

1.

What’s the output of the program above? (25P)

void traverse(Node* v) {

stack<Node*> stl_stack;

stl_stack.push(v);

while (!stl_stack.empty()) {

Node* current = stl_stack.top();

if ((current->right == NULL)

&& (current->left == NULL)) 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 below?

(25P)

8 4

2 6

3

5 7

12

10 14

9 11 13 15

1

(2)

void insertOrdered(DoublyNode* newNode, DoublyNode* current) {

if(... && ...) insertOrdered(newNode, current->next);

else {

newNode->next = current->next;

newNode->prev = current;

current->next->prev = newNode;

current->next = newNode;

} }

int main() {

DoublyLinkedList list; DoublyNode* newNode;

newNode = new DoublyNode;

newNode->elem = "Paul"; newNode->score = 720;

list.insertOrdered(newNode, list.header);

newNode = new DoublyNode;

newNode->elem = "Rose"; newNode->score = 590;

list.insertOrdered(newNode, list.header);

newNode = new DoublyNode;

newNode->elem = "Anna"; newNode->score = 660;

list.insertOrdered(newNode, list.header);

newNode = new DoublyNode;

newNode->elem = "Mike"; newNode->score = 1105;

list.insertOrdered(newNode, list.header);

}

3.

Complete the function insertOrdered(). (25P) Assume that Trailer’s score is 0.

You’ll loose 5P from wrong answer.

(A) if ((newNode->score >= current->score) && (current != trailer))

(B) if ((newNode->score >= current->next->score) && (current != trailer))

(C) if ((newNode->score >= current->score) && (current->next != trailer))

(D) if ((newNode->score >= current->next->score) && (current->next != trailer))

Zig

1

2 6

5 3

4

Zig-Zig Zig-Zig Zig Zig-Zig Zig-Zig Zig

4.

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

1

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