Tuesday 14 May 2013

C++ Stack - Part 1


Part one covers only the class interface of the stack. Basically, a stack is a data type which follows Last-In-First-Out rule.



#ifndef STACK_H
#define STACK_H    

using namespace std;

class stack
{
    public:
        stack();    // Constructor
        ~stack();  // Destructor
        bool Push(int x); // A Function that inserts an element into the stack 
        bool Pop(); // A Function that deletes an element from the stack        
        bool IsEmpty(); // A function that determines if the stack is empty
        bool IsFull(); // A function that determines if the stack is full
        void Print(); // A Function that prints all elements in the stack
        int getSize(); // A function that returns the number of elements in the stack
                 
    private:
        int top; // A variable that indicates the position of the last element
        int arrayStack[10]; // An array that contains the elements of the stack

};
#endif

Your file name is very important here, because in Part two, which will be the function definitions and implementation will be used.

No comments:

Post a Comment