Lab 5: Queue from 2 Stacks (100 pts)
Due Monday, May 14 at 9:20am on Canvas


Pair Programming Extra Credit Opportunity (5 pts)

  • Both partners fill in, sign and date the pair programming contract (Both partners).
  • Only ONE partner submits the lab assignment on Canvas. Please make sure both your names are on ALL the files.

Your Objective
  • Here is a common interview question: implement a queue using two stacks.
  • We will create an implementation of this interview question for Lab 5, and you will then be ready if you are asked this question on your next interview!
  • Given the below header file (must remain unchanged), write the Queue functions whose prototypes are provided in a file named Queue.cpp.
  • Test your functions inside a test file named QueueTest.cpp
  • Name your header file Queue.h and your source file Queue.cpp
  • These files should be placed inside of a C++ project in Eclipse, along with your Stack.h from Lab 3.


Queue.h

  • Copy and paste the below code into a file named Queue.h.
  • You are not permitted to alter anything about this file.
  • Note: This file is not to be submitted.
    • The instructor will test your code using the below file.
  • Thus, make sure your source code compiles with the given header file.


#ifndef QUEUE_H_
#define QUEUE_H_


#include <iostream>
#include "Stack.h"
using namespace std;

class Queue
{
    public:
      
        /**manipulation procedures*/

        void dequeue();
        //removes an element from the front of the queue
        //precondition: the queue is not empty
        //postcondition: an element has been removed from the front of the queue

        void enqueue(int data);
        //adds an element to the end of the queue
        //postcondition: an element added to the end of the queue

        /**accessors*/

        int getFront() const;
        //returns the element at the front of the queue
        //precondition: the queue is not empty

        int getSize() const;
        //returns the size of the queue

        bool isEmpty() const;
        //returns whether the queue is empty

        /**additional queue operations*/
        void display(ostream& out) const;
        //prints the elements in the queue to out


    private:
        Stack<int> s1;
        Stack<int> s2;

};



#endif /* QUEUE_H_ */



What to Submit

  • Submit your Stack.h, Queue.cpp and QueueTest.cpp files to Canvas when you are finished.
  • -15 points for a missing test file
  • -14 points for each missing or incorrect function
  • No credit if your code does not compile with the above header file.
  • No credit if your code does not compile.