Homework # 4 (Due Date: Wednesday August 10 in class)

Submit your homework via E-learning

Select your 3 code files (main.cpp, linkedStackType.h, and TwoStackQueue.h) and compress them into a file named StudentID_FirstName.zip
Note: use Winrar to compress your files.

A queue can also be implemented using two stacks. One stack is used to enqueue elements, while the other is used to dequeue elements. That is, when an element is added to the queue it is pushed into the in stack. When an element is removed from the queue it is popped off the out stack. If the out stack is empty, the content of the in stack is transferred to the out stack.

download linkedStackType.h and TwoStackQueue.h here.

TwoStackQueue class


#include "linkedStackType.h"

template <class Type>
class TwoStackQueue

	TwoStackQueue ();

	~TwoStackQueue ();

	bool IsEmpty () const;

	bool IsFull () const;

	Type Front () const;

	Type Back () const;

	void addQueue (const Type& newElement);

	void deleteQueue ();

	linkedStackType<Type> in;
	linkedStackType<Type> out;
...			// functions definitions here 


addQueue: adds an element to the queue by pushing it into in Stack.

deleteQueue: removes an element from the queue by popping it from out Stack. If out Stack is empty, pop all elements in in Stack and push them into out Stack then pop an element from out Stack. The operation can not proceed when both stacks are empty.