CSCI 261 - Programming Concepts - Spring 2022

Lab 6B - Processing Ordered Lists

This lab is due by Thursday, April 21, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.


Instructions


This lab will implement a Stack and a Queue data structure.

The following main.cpp will be used to test our Stack and Queue implementations.

#include "Stack.hpp"
#include "Queue.hpp"

#include <iostream>
using namespace std;

int main() {
    Stack<int> stacker;
    stacker.push(1);
    stacker.push(2);
    stacker.push(3);
    stacker.push(4);
    stacker.push(5);
    while( !stacker.isEmpty() ) {
        cout << "stack top is: " << stacker.peak() << " \t";
        int top = stacker.pop();
        cout << "stack top was: " << top << endl;
    }
    cout << "stack is empty" << endl;

    cout << endl;

    Queue<int> queuer;
    queuer.push(1);
    queuer.push(2);
    queuer.push(3);
    queuer.push(4);
    queuer.push(5);
    while( !queuer.isEmpty() ) {
        cout << "queue front is: " << queuer.peak() << "\t";
        int front = queuer.pop();
        cout << "queue front was: " << front << endl;
    }
    cout << "queue is empty" << endl;

    return 0;
}

Note that the interface for each is the same: void push(T), T peak(), T pop(), bool isEmpty(). The only difference between the two is the peak() and pop() behavior:

The expected output of the program is as follows (note the LIFO and FIFO behavior):

stack top is: 5         stack top was: 5
stack top is: 4         stack top was: 4
stack top is: 3         stack top was: 3
stack top is: 2         stack top was: 2
stack top is: 1         stack top was: 1
stack is empty

queue front is: 1       queue front was: 1
queue front is: 2       queue front was: 2
queue front is: 3       queue front was: 3
queue front is: 4       queue front was: 4
queue front is: 5       queue front was: 5
queue is empty

It would be in your best interest to create the Stack and Queue classes as templated classes in their own files to make use in future tasks.


Lab Submission


Submit your main.cpp, Makefile, *.hpp, *.h, *.cpp file(s).

You will submit your solution to this lab with the rest of Set6. Detailed instructions for doing this are posted in Assignment 6.


This lab is due by Thursday, April 21, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.