Stack using LL

Stack.h
#include "Singly LL.h"
#pragma once 

template<typename T>class Stack{
    SinglyLL<T> list;
public:
    bool isEmpty();
    bool isFull();
    void Push(const T val);
    bool Pop(T& val);
    T top();
};

template<typename T> T Stack<T> :: top() {
    SinglyLL<T> cur(list);
    T temp;
    cur.removeAtHead(temp);
    return temp;
}

template<typename T>bool Stack<T> :: isEmpty() {
    return list.Empty();
} 

template<typename T>bool Stack<T> :: isFull() {
    return false;
}

template<typename T>void Stack<T> :: Push (const T val) {
    list.insertAtHead(val);   
}

template<typename T>bool Stack<T> :: Pop (T& val) {
    if(isEmpty()) return false;
    
    list.removeAtHead(val);
    return true;
}

Last updated

Was this helpful?