Wednesday, 24 June 2015

Stack

/*
Tanzila Islam
CSE, Southeast University.
Dhaka-Bangladesh.
id : https://www.facebook.com/prieontypurnotamohita
mail: tanzilamohita@gmail.com
blog: http://tanzilamohita.blogspot.com/

*/


#include <iostream>

using namespace std;


const int MAX_SIZE = 10000;


class Stack {

private:

    int array[MAX_SIZE];

    int top;


public:

    Stack() {

        top = 0;

    }


    void push(int x) {

        array[top] = x;

        top++;

    }


    int pop() {

        top--;

        return array[top];

    }


    int peek() {

        return array[top - 1];

    }


    bool isEmpty() {

        if (top == 0)

            return true;

        else return false;

    }

};


int main() {

    Stack s;

    s.push(10);

    s.push(13);

    s.push(15);


    while (!s.isEmpty())

        cout << s.pop() << endl;

    return 0;

}

No comments:

Post a Comment