Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Stos
- {
- int wartosc;
- Stos *next;
- };
- void PUSH(Stos **root)
- {
- Stos *nowa = new Stos;
- cout<< "\nPodaj wartosc: ";
- cin>>nowa->wartosc;
- nowa->next=*root;
- *root=nowa;
- }
- void POP(Stos **root)
- {
- if (*root)
- {
- Stos *temp = *root;
- *root=(*root)->next;
- cout<< "\nUsunieto wartosc: " << temp->wartosc;
- delete temp;
- }
- else cout<< "\nBrak elementow na stosie";
- }
- void Stos_LIFO()
- {
- Stos *root = NULL, *nowa = NULL;
- char i;
- do{
- cout<< "\n" << setw(45) << "MENU";
- cout<< "\n1. PUSH \n2. POP \n0. Wyjscie do menu glownego";
- cout<< "\n\nPodaj opcje: ";
- cin>> i;
- switch (i)
- {
- case '1': //dodaj element do stosu
- PUSH(&root);
- break;
- case '2':
- POP(&root); //zdejmi element ze stosu
- break;
- case '0':
- break;
- default:
- cout<< "\nPodano bledna opcje. Prosze sprobowac ponownie.";
- break;
- }
- }while(i != '0');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement