Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <windows.h>
- #include <cstdio>
- struct el_LIFO
- {
- int x;
- struct el_LIFO* nast;
- };
- struct el_LIFO* push(struct el_LIFO *top, int el)
- {
- struct el_LIFO * new_el_LIFO=(struct el_LIFO*)malloc(sizeof(struct el_LIFO));
- new_el_LIFO->x=el;
- new_el_LIFO->nast=top;
- return new_el_LIFO;
- }
- struct el_LIFO* pop(struct el_LIFO *top, int *el)
- {
- struct el_LIFO* temp;
- if(top!=NULL)
- {
- *el=top->x;
- temp = top-> nast;
- free(top);
- return temp;
- }
- else {return NULL;}
- }
- struct el_LIFO* display(struct el_LIFO *top)
- {
- if(top==NULL)
- std::printf("Brak elementów\n");
- else
- do{
- std::printf("%5d\n",top->x);
- top=top->nast;
- }while (top!=NULL);
- }
- struct el_LIFO cleaning(struct el_LIFO *top)
- {
- if (top==NULL) return ;
- stack *e;
- while(top)
- {
- e = (top)->nast;
- delete top;
- top = e;
- }
- }
- int top_el(struct el_LIFO *top, int *el)
- {
- if(top!=NULL)
- {
- *el=top->x;
- return 1;
- }
- else{return 0;}
- }
- int main()
- {
- struct el_LIFO *top_LIFO=NULL;
- for(;;)
- { int choose;
- std::cout<<"MENU"<<std::endl;
- std::cout<<"1. Stwórz stos"<<std::endl;
- std::cout<<"2. Dodaj element na stos"<<std::endl;
- std::cout<<"3. zdejmij element ze stosu"<<std::endl;
- std::cout<<"4. Pokaż wierzchołek stosu"<<std::endl;
- std::cout<<"5. Pokaż stos"<<std::endl;
- std::cout<<"6. Koniec programu"<<std::endl;
- std::cin>>choose;
- switch(choose)
- {
- case 1:
- break;
- case 2:
- int toTop;
- std::cout<<"Podaj liczbe ktora chcesz wrzucic na szczyt" <<std::endl;
- std::cin>>toTop;
- top_LIFO=push(top_LIFO,toTop);
- break;
- case 3:
- if(top_LIFO!=0)
- {
- int toPop,d;
- top_LIFO=pop(top_LIFO,&d);
- std::cout<< "usunieto: "<<d<<std::endl;
- system("PAUSE");
- }
- break;
- case 4:
- int t;
- if(top_el(top_LIFO,&t))std::cout<<"wierzcholek: "<< top_LIFO->x<<std::endl;
- else std::cout<<"Stos pusty."<<std::endl;
- system("PAUSE");
- break;
- case 5:
- display(top_LIFO);
- system("PAUSE");
- break;
- case 6:
- return 0;
- break;
- }
- system("CLS");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement