Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- struct stos
- {
- int data;
- stos* next;
- };
- bool is_Empty(stos *st);
- void push (stos* &st, int new_data);
- void pop(stos* &st);
- void take_element(stos* st);
- int main()
- {
- int w;
- stos* st = nullptr;
- st = new stos[10];
- srand(time(NULL));
- //st = 0;
- while (w!=5){
- cout << " 1 - sprawdzenie czy stos jest pusty" << endl;
- cout << " 2 - dodanie elementu na stos" << endl;
- cout << " 3 - usuniecie ze stosu" << endl;
- cout << " 4 - pobranie elementu ze stosu" << endl;
- cout << " 5 - wyjscie z programu" << endl;
- cout << " Co chcesz zrobic?" << endl;
- cin >> w;
- switch (w)
- {
- case 1: is_Empty(st); break;
- case 2: push (st,rand()); break;
- case 3: pop(st); break;
- case 4: take_element(st); break;
- case 5: cout << "juz nic nie mozesz zrobic " << endl; break;
- default: cout << " Bledny wybor" << endl;
- }
- }
- return 0;
- }
- bool is_Empty(stos* st){
- if(st == 0) cout << " Stos jest pusty" << endl;
- else{
- cout << " W stosie cos jednak bylo" << endl;
- return st == nullptr;
- }
- }
- void push (stos* &st, int new_data){
- cout << new_data << endl;
- stos* dodana_wartosc = new stos;
- dodana_wartosc -> data = new_data;
- dodana_wartosc -> next = st;
- st = dodana_wartosc;
- }
- void pop(stos* &st){
- if(st != 0){
- stos* temp = st;
- st = st -> next;
- delete temp;
- cout << "Usuwanie powiodlo sie" << endl;
- }
- else
- cout << "Usuwanie nie powiodlo sie, stos jest pusty" << endl;
- }
- void take_element(stos* st){
- if (st == 0)
- cout << "stos jest pusty" << endl;
- else{
- cout << "na gorze stosu jest liczba :" << st -> data << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement