Professional Documents
Culture Documents
(2018) Data Models and Algorithms (Aidm313)
(2018) Data Models and Algorithms (Aidm313)
FINAL EXAMINATION
INSTRUCTIONS TO CANDIDATE
1. Answer ALL questions in Section A, B and C
2. Write all your answers in the answer booklet provided.
3. If you make a mistake please put a single diagonal line through the
section you wish to be ignored by the examiner.
4. Return all examination papers and scripts upon completion of the
examination including any workings.
AIDM313 · DATA MODELS & ALGORITHMS
AUG – DEC 2018 FINAL EXAMINATION
1.
Based on the array-based implementation of class Stack discussed in the
class with the following data members:
Class Stack{
// public function declarations here
private:
static const int Size = 10;
int Array[Size];
int top; /* array index of top element of the stack; is -1 when stack is empty */
};
Write a member function void Stack::push(int newItem)
throw(StackException) which pushes newItem onto the stack and
throws an exception if the stack is full. (5)
which checks to see if two stacks are equal that is to say they have
the same number of items, and all these items, from the top to the
bottom, are equal. (8)
top: 4
items: 8 0 0 4 7 10 -34323 0 67823 -78999
while (!bStack.isEmpty()){
bStack.pop(x);
if (x>0 && !bStack.isEmpty())
bStack.pop();
cout << x << endl;
}
4. Describe in your own words the idea of the Insertion sort algorithm for
arrays with an example. (6)