SJSU CMPE 126 F19 –Midterm Exam 2
First:________________ Last:________________ Last 4 id:_____
Assume there is a stock class which has symbol (string), cost (int) and shares (int) as private members. There is also a stockNode class which inherits stock class and has prev/next as needed. Further assume there are classes for storing collection of stock as follows:
DBfwd.. stores stocks in a forward linked list
DBdlink.. stores stocks in a doubly-linked list
(2pt) Give two reasons for using linked list, instead of array
______________________________________________________________
______________________________________________________________
(2pt) Write the minimum declarations for DBdlink (hint:constructor/destructor/etc?)
(3pt) Write an insert member function for DBdlink which inserts a node (pointered by np) at the nth position.
void DBdlink::insert(stockNode *np, int n) {
(3pt) Write a reverse member function for DBfwd which reverse the list. Assuming first is the only data members of DBfwd.
void DBfwd:reverse() {
(3pt) Write a deleteBackNth function for DBfwd which deletes nth node from the back. Assuming first is the only data members of DBfwd.
void DBfwd::deleteBackNth(int n) {
(2pt) Comparing with iterative function, what's the biggest advantage/disadvantage of recursive implementation?
advantage: __________________________________________________
disadvantage:___________________________________________________
(3pt) Give an integer array, using recursion method to find the max number
int largest(const int list[], int lowerIndex, int upperIndex)
(3pt) Write the function that solves the Tower Of Hanoi problem.
void TowerOfHanoi ( int n, char src, char dst, char temp) // n number of disc
(4pt) Convert the following infix/postfix expressions to postfix/infix notations respectively: (use the space below as your scratchpad so we know the answer is genuine)
A – (B + C) * D + E / (F – G)
2 3 4 + 5 6 - - *