Vectors, Stacks, and Queues
Due: 28 Sep 2011
Educational objectives:
- Primary objectives: Experience implementing vector, stack, and queue classes, using recursive function calls, analyzing the runtime of your code.
- Secondary objectives: Implementing and using templates.
Statement of work: (i) Implement generic vector, stack, and queue classes, (ii) evaluate a recursive function, and (iii) analyze time complexities.
Deliverables:
- Turn in a
makefileand all header (*.h) and cpp (*.cpp) files that are needed to build your software, as described in www.cs.fsu.edu/~asriniva/courses/DS11/HWinstructions.html. Turn in your development log too, which should be a plain ASCII text file calledLOG.txtin your project directory.Requirements:
- Create a subdirectory called
proj2.- You will need to have a
makefilein this directory. In addition, all the header and cpp files needed to build your software must be present here, as well as theLOG.txtfile.- You should create the following additional files.
- Vector.h: This should implement a generic
Vectorclass (note the capitalization of the first letter inVector). The following features must be implemented: (i) a default constructor that initializes an array of size 2, (ii) a destructor, (iii) void push_back(const T &e), (iv) the operator[], (v) int size( ) const, (vi) void push_front(const T &e), (vii) void pop_front() and (vii) void pop_back(). The time complexities of these operators should be as good as feasible in a vector. When the array capacity is exhausted, the array size should be increased by a factor of 4. You may implement additional features, if you wish to. If you do not implement a copy constructor and an assignment operator, then you should prevent their use by making them private.
- stack.h: Use the
Vectorclass to implement a genericstackclass with at least the following features: (i)void push(T &), (ii)void pop(), (iii)T &top(), and (iv)bool empty(). The amortized time complexities for all operations should be O(1).
- queue.h: This should implement a generic
queueclass with at least the following features: (i)void push(T &), (ii)void pop(), (iii)T &front(), and (iv)bool empty(). The amortized time complexities for all operations should be O(1).
- Other files: You may use more files.
- main.cpp: This is a program to evaluate a recursive function. The command:
./recurse N1 C1 A1 M1 M2 M3 M4 D1 D2 S1 S2 Arg Opwill cause the function given below to be evaluated recursively and the answer output. The function is defined as follows.
f(N) = 0, ifN < N1
f(N1) = C1
f(N)= A1 + M1*f(M2*N/D1 - S1) Op M3*f(M4*N/D2 - S2), ifN > N1Here,
f(Arg)needs to be evaluated. N1 C1 A1 M1 M2 M3 M4 D1 D2 S1 S2, Arg are integers and Op is either+or-. The division performed is the usual integer division with truncation.Example:
Prompt> ./recurse 2 3 2 1 2 0 1 3 6 0 0 18 +
13(program output)- Analysis.txt: This should be a plain ASCII text file in which you give the time complexities for the following. (i) The recursive implementation as a function of all arguments to the executable
recursewhich influence the running time of that program. For the analysis alone, assume thatS1 = S2 = 0,M2 = M4 = 1, andD1 = D2. (ii) Thepush_frontoperation on theVectorclass. Briefly justify the results of your analysis.Sample executable: A sample executable is available at ~cop4530/fall11/solutions/proj2/recurse on
linprog. The first person to find errors in our program will get a bonus point!Notes:
- You should not use the STL
list,vector,deque,stack, orqueueclasses. You may use thestringclass. Please get my written permission before using any other STL feature.- We will test your
Vector,stack, andqueueclasses on entirely different applications. So it is important for these classes to be generic and exactly as specified.- You will get 5 bonus points if, in addition to the recursive implementation of the above function, you also provide an iterative implementation that explicitly uses a
stackobject to simulate the recursive implementation. This implementation should be in a file calledRecurseStack.cppand the corresponding executable should be namedRecurseStack. Please email Shen Dong if you submit this additional file.
Last modified: 14 Sep 2011