سورس پشته ( Stack )

جمعه 12 بهمن 1397
10:39
smartdevelop


#include
#include
using namespace std;
#define MAX 11

class Stack {
    int top;
public:
    int a[MAX];    

    Stack() {
        top = -1;
    }
    bool push(int x);
    int pop();
    bool isEmpty();
};

bool Stack::push(int x) {
    if (top >= (MAX - 1)) {
        cout << "Stack Overflow";
        return false;
    }
    else {
        a[++top] = x;
        cout << x << " pushed into stack\n";
        return true;
    }
}

int Stack::pop() {
    if (top < 0) {
        cout << "Stack Underflow";
        return 0;
    }
    else {
        int x = a[top--];
        return x;
    }
}

bool Stack::isEmpty() {
    return (top < 0);
}


int main() {
    cout << "********************************************************" << endl;
    cout << "             smartdevelop.ir" << endl;
    cout << "********************************************************" << endl;
    struct Stack s;
    int shomare;
    for (int i = 0;i <= 10;i++) {
        cout << "adad somare " << i << " ra vared konid :";
        cin >> shomare;
        s.push(shomare);
    }
    for (int i = 0;i <= 10;i++) {
        cout << s.pop() << " Popped from stack\n";
    }
    getch();

    return 0;
}

 

 

از کتابخانه های  iostream  و  conio.h  استفاه کنید

سورس : دانلود

 

 

 

 

 

 

 

 

 

 


ورود کاربران

خوش آمدید! لطفا وارد حساب خود شوید

رمز عبور را فراموش کرده‌اید؟
حساب کاربری ندارید؟

فراموشی رمز عبور

نام کاربری یا ایمیل خود را وارد کنید

یا

ثبت نام کاربران

در چند ثانیه حساب کاربری خود را بسازید

قبلا ثبت نام کرده‌اید؟

نظرات کاربران

دیدگاه خود را با ما در میان بگذارید