Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Slack {
- int size, quantity;
- bool if_exist;
- int* tab;
- public:
- Slack(int x = 10) {
- cout << "To jest konstruktor!: "<<this << endl;
- init(x);
- }
- ~Slack() {
- cout << "To jest destruktor!: " <<this << endl;
- destroy();
- }
- void init(int x) {
- if_exist = true;
- tab = new int[x];
- size = x;
- quantity = -1;
- }
- void push(int x) {
- if (if_exist == false) { cout << "There is no slack!" << endl; return; }
- else if (quantity < size - 1) {
- quantity++;
- tab[quantity] = x;
- if_exist = true;
- }
- else cout << "There is no space!" << endl;
- }
- void pop() {
- if (if_exist == false) { cout << "There is no slack!" << endl; return; }
- else if (quantity < 0) cout << "There is nothing to pop!" << endl;
- else {
- tab[quantity] = 0;
- quantity--;
- }
- }
- int top() {
- if (if_exist == false) { cout << "There is no slack!" << endl; return -1; }
- else if (quantity < 0) { cout << "There is nothing to show!" << endl; return -1; }
- else {
- return tab[quantity];
- }
- }
- bool empty() {
- if (if_exist == false) { cout << "There is no slack!" << endl; return false; }
- if (quantity < 0) {cout << "It's empty, True!" << endl; return true;}
- else cout << "It's NOT empty, False!" << endl; return false;
- }
- bool full() {
- if (if_exist == false) {cout << "There is no slack!" << endl; return false;}
- if (quantity >= size - 1) {cout << "It is full, True!" << endl; return true;}
- else cout << "It is NOT full, False!" << endl; return false;
- }
- void destroy() {
- size = 0;
- quantity = 0;
- if_exist = false;
- delete[] tab;
- }
- };
- void f(Slack s, int a) {
- s.push(a);
- }
- int main() {
- Slack s;
- s.push(0);
- f(s, 1);
- f(s, 2);
- while (!s.empty()) {
- cout <<
- s.top();
- s.pop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement