{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SYSC2002_2003_Fall

# SYSC2002_2003_Fall - Question 1(7 8 = 15 marks This...

This preview shows pages 1–4. Sign up to view the full content.

Page 1 of 9 Question 1 (7 + 8 = 15 marks) This question assumes the class outlined below. Note that only those aspects of the class that are relevant to the question have been shown. Other aspects have been omitted. A full class definition would include a constructor, a destructor, and so on. class X { private: class LNode { int data; LNode *next, *prior; LNode (int data, LNode *next, LNode *prior) { this -> data = data; this -> next = next; this -> prior = prior; } }; LNode *head, *tail; int count; public: // Duplicates the last value in the list. If a list contains {1, 2, 2, 6, 8}, this method // will leave it containing {1, 2, 2, 6, 8, 8}. Throws a “range_error” exception if // the list is empty. void duplicateLastNode (); // Deletes all list nodes containing a value greater than “limit”. // If there are no such nodes the method has no effect. void deleteAllGreaterThan (int limit); }; The class involves a doubly linked list. This list is sorted in ascending order and may contain duplicate values. In the space provided in your answer booklet, implement methods “duplicateLastNode” and “deleteAllGreaterThan”.

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

View Full Document
Page 2 of 9 Question 2 (7 marks) In the space provided in your answer booklet, write a recursive function that reverses the order of elements “start” through “end” of an array (as illustrated below). start end BEFORE 0 3 5 4 2 1 start end AFTER 0 2 4 5 3 1 A function header has been supplied: // Reverses the order of array elements “start” through end” void reverseElements (int array[], int start, int end); Make you own decision as to how your function should behave if “start” is greater than “end”. Any reasonable choice is acceptable. Hint: there is one very reasonable choice that will make your life much easier.
Page 3 of 9 Question 3 (7 + 8 = 15 marks) This question assumes the class outlined below. Note that only those aspects of the class that are relevant to the question have been shown. Other aspects have been omitted.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 9

SYSC2002_2003_Fall - Question 1(7 8 = 15 marks This...

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

View Full Document
Ask a homework question - tutors are online