Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- struct stack {
- int val;
- stack *next;
- };
- struct stose
- {
- stack *H;
- int size;
- stose()
- {
- H = NULL;
- size = 0;
- }
- void push();
- void pop();
- void czubek();
- };
- int main()
- {
- stose stosik;
- int wybor;
- bool exit = 0;
- while (!exit) {
- cout << " 1.PUSH \n 2.POP \n 3.CZUBEK \n 4.EXIT ";
- cin >> wybor;
- cout << "\n";
- switch (wybor) {
- case 1: stosik.push();
- break;
- case 2: stosik.pop();
- break;
- case 3: stosik.czubek();
- break;
- case 4: exit = 1;
- break;
- }
- }
- return 0;
- }
- void stose::push()
- {
- stack *p = new stack;
- cout << "Podaj wartosc do dodania: ";
- cin >> p->val;
- p->next = H;
- H = p;
- size++;
- system("cls");
- }
- void stose::pop()
- {
- if (H)
- {
- stack* tmp = H;
- H = H->next;
- delete tmp;
- }
- size--;
- system("cls");
- }
- void stose::czubek()
- {
- if (H != NULL)
- {
- stack* p = H;
- cout << "Na czubku stosu znajduje sie liczba: " << p->val << endl;
- }
- else
- {
- cout << "Stos jest pusty! \n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement