Tuesday, July 14, 2009

I need a sample exam and answers on the dynamic data structures in C++(Pointers,Linked Lists &recursion)?

You have not stated how complex you want this exam to be. I could very easily ask questions and give answers that would not be reasonable to ask at a first year bachelors level but would be at a first year graduate level. However I will assume this is a test at a first year post secondary level.





--------------------------------------...


(1) Q: Write a funtion that prints out the contents of a singly linked list in reverse. (hint use recursion)





A:


void write_reverse(Element *first){


__if (first){


______write_reverse(first -%26gt; next );


______cout %26lt;%26lt; first -%26gt; data %26lt;%26lt; ' ';


__}


}





(2) Q: Write a funtion that uses recursion to place an element at the end of a singly linked list.





A:


void put_last_rec( Element *%26amp; first, int d){


__if (! first)


____first = new Element(0, d);


__else


____put_last_rec(first -%26gt; next , d );


}





(3) Q: Describe what the following code is:





class unknown {


public


__unknown *forward, *backward;


__int data;


__unknown(unkown *f=0, unknown *b=0, int d=0)


____ : forward(f), backward(b), data(d) {}


};





A: This is a class for a doubly linked list with values of type int. This class contains two pointers, an integer, a constructor for constructing new lists which also acts as a default constructor.





--------------------------------------...


This exam has pointers, linked lists, and recursion and should be of decent difficulty for an introduction to programming type class. Hope this helps.

survey

No comments:

Post a Comment