SYSC2002_2006_Fall

SYSC2002_2006_Fall - SYSC 2002 A & B Fall 2006 Final...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
SYSC 2002 A & B Fall 2006 Final Exam Page 1 of 4 Note: Typos in the exam have been fixed in underlined red type. Question 1 (7 Marks) Write a function that, given an array of integer values and the number of values in this array, creates a doubly linked list containing the same values and returns the head pointer for this list. Assume the node definition below. The order of the values must be preserved. The first value in the array must wind up at the head of the linked list and so on. struct LNode { int data; LNode *next, *prior; }; Question 2 (18 Marks) The tree class definition outlined below involves "threaded" trees (recall assignment #8). Nodes without a right child have a pointer to the tree node containing the next higher value. class Tree { private: class TNode { public: int data; TNode *left, *right, *nextHighest; . . . }; TNode *root; public: bool limitedDelete (int value); bool operator== (const Tree &otherTree) const; } For both parts of this question recursion is permitted but not required, and you must fully implement any private member methods that you might want to use. (a) (9 marks) Give the implementation of method "limitedDelete". To keep things simple, your function need only be capable of deleting values that are stored in a leaf node. If the specified value does not exist anywhere in the tree, your function should return false. Otherwise it should either delete the value and return true (if the value is in a leaf node) or throw an "invalid_argument" exception (if the value is not in a leaf node). Your function must, of course, deal properly with the "threaded" aspect of the tree. You should be able to work out what is required.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

SYSC2002_2006_Fall - SYSC 2002 A & B Fall 2006 Final...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online