UoM-EECS402 / Project4 / LIFOStackClass.h
LIFOStackClass.h
Raw
#ifndef _LIFOSTACKCLASS_H_
#define _LIFOSTACKCLASS_H_

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

//Programmer: Youngjun Woo
//Date: November 18, 2021
//Purpose: This class will be used to store a simple last-in-first-out stack 
// data structure.

class LIFOStackClass
{
  private:
    LinkedNodeClass *head;
    // Points to the first node in a stack, or NULL if stack is empty.
    
    LinkedNodeClass *tail;
    // Points to the last node in a stack, or NULL if stack is empty.
  
  public:
    LIFOStackClass();
    // Default Constructor. Will properly initialize a stack to be an empty 
    // stack, to which values can be added.

    ~LIFOStackClass();
    // Destructor. Responsible for making sure any dynamic memory associated 
    // with an object is freed up when the object is being destroyed.

    void push(const int &newItem);
    // Inserts the value provided (newItem) into the stack.

    bool pop(int &outItem);
    // Attempts to take the next item out of the stack. If the stack is empty, 
    // the function returns false and the state of the reference parameter 
    // (outItem) is undefined. If the stack is not empty, the function returns 
    // true and outItem becomes a copy of the next item in the stack, which is
    // removed from the data structure.

    void print() const;
    // Prints out the contents of the stack. All printing is done on one line, 
    // using a single space to separate values, and a single newline character 
    // is printed at the end.

    int getNumElems() const;
    // Returns the number of nodes contained in the stack.

    void clear();
    // Clears the stack to an empty state without resulting in any memory leaks.
};

#endif