Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #define MAXSIZE 100
- using namespace std;
- struct array_stuck
- {
- int nTop;
- int nCapacity;
- int *arr;
- };
- void initial(array_stuck &s);
- bool isEmpty(array_stuck s);
- bool isFull(array_stuck s);
- void push(array_stuck &s, int nData);
- int pop(array_stuck &s);
- int main()
- {
- array_stuck s;
- initial(s);
- push(s, 5);
- push(s, 6);
- cout << pop(s) << endl;
- cout << pop(s) << endl;
- cout << pop(s) << endl;
- system("pause");
- return 0;
- }
- int pop(array_stuck &s)
- {
- if (isEmpty(s))
- return INT_MIN;
- else
- return s.arr[s.nTop--];
- }
- void push(array_stuck &s, int nData)
- {
- if (isFull(s))
- cout << "array_stuck overflow!\n";
- else
- s.arr[++s.nTop] = nData;
- }
- bool isFull(array_stuck s)
- {
- return s.nTop == s.nCapacity - 1;
- }
- bool isEmpty(array_stuck s)
- {
- return s.nTop == -1;
- }
- void initial(array_stuck &s)
- {
- s.nCapacity = MAXSIZE;
- s.nTop = -1;
- s.arr = new int[s.nCapacity];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement