#include <cstdlib> #include <iostream> #include <conio.h> using namespace std; STRUCT elem { INT dane; elem *nast; }; void push(elem *&stos, INT x); INT pop(elem *&stos); INT topEl(elem *stos); bool isEmpty(elem *stos); void usun(elem *&stos); INT count(elem *stos); INT main(INT argc, char *argv[]) { unsigned INT option = 0; INT liczba = 0; elem *stos = NULL; WHILE(option!=7) { cout << "\n\n\n\n1. Polozenie elementu na wierzcholku stosu " << endl; cout << "2. Pobranie ostatnio odlozonego elementu i zwrocenie go jako wartosci funkcji " << endl; cout << "3. Zwrocenie elementu znajdujacego sie na wierzcholku stosu bez jego usuwania " << endl; cout << "4. Sprawdzenie czy stos jest pusty " << endl; cout << "5. Usun stos " << endl; cout << "6. Zlicz elementy na stosie " << endl; cout << "7. Koniec programu " << endl; cout << "\n\n\nWybierz opcje " << endl; cin >> option; SWITCH (option) { CASE 1: cout << "Podaj dowolna liczbe" << endl; cin >> liczba; push(stos, liczba); cout << "Polozono element na wierzcholek stosu" << endl; BREAK; CASE 2: cout << "Pobrany element ze szczytu stosu " << pop(stos) << endl; BREAK; CASE 3: cout << "Pobrany element z wierzcholku stosu bez usuwania " << topEl(stos) << endl; BREAK; CASE 4: IF (isEmpty(stos)) cout << "stos jest pusty" << endl; ELSE cout << " stos nie jest pusty" << endl; BREAK; CASE 5: usun(stos); cout << "Usunieto caly stos" << endl; BREAK; CASE 6: cout << "Ilosc elementow w stosie: " << count(stos) << endl; BREAK; } } RETURN 0; } //================================================ void push(elem *&stos, INT x) { elem *e = new elem; e->dane = x; e->nast = stos; stos = e; } //================================================ INT pop(elem *&stos) { elem *e; IF (stos == NULL) { cout <<"pusty stos" << endl; RETURN -121; } INT zwr = stos->dane; e = stos->nast; delete stos; stos = e; RETURN zwr; } //================================================ INT topEl(elem *stos) { IF (stos == NULL) { cout <<"pusty stos" << endl; RETURN -121; } INT zwr = stos->dane; RETURN zwr; } //================================================ bool isEmpty(elem *stos) { IF (stos == NULL) { RETURN true; } ELSE RETURN false; } //================================================ void usun(elem *&stos) { elem *e; WHILE(stos) { e = stos->nast; delete stos; stos = e; } } //================================================ INT count(elem *stos) { IF (stos == NULL) RETURN 0; INT il = 0; WHILE(stos) { stos = stos->nast; ++il; } RETURN il; }