Stacks

Last In First Out (LIFO)

  • Top
  • Push
  • Pop

Numerous applications:

  • Compilers, to push function calls into the stack
  • Parsing (like parsing XHTML)

Can be implemented via

  • Arrays
  • Singly linked list

    Two references to the head and tail of the list: list_head and list_tail

Class Singly Linked List

class Single_list {
    public:
        Single_list();
        ~Single_list();

        int size() const;
        int 

};

Class Stack

template <typename Type>
class Stack {
    private:
        Single_list<Type> list;

    public:
        bool empty() const;
        Type top() const;

        void push(Type);
        Type pop();
};

In [ ]: