Facebook
From Mazur Głazur, 3 Years ago, written in Plain Text.
This paste is a reply to Untitled from Mazur Głazur - view diff
Embed
Download Paste or View Raw
Hits: 187
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. struct stos{
  8. int liczba;
  9. stos* next;
  10. };
  11.  
  12. void push(stos**top);
  13. void wyswietlanie(stos*top);
  14. int generowanie();
  15. void usuwanie(stos**top);
  16.  
  17. int main()
  18. {
  19.     cout << "Kacper Walenkiewicz" <<endl;
  20.  
  21.     int x,n;
  22.     bool br=true;
  23.  
  24.     stos* top = NULL;
  25.  
  26.     do{
  27.     cout<<endl<<"---------Menu---------\n1.Sprawdzenie czy stos jest pusty\n2.Dodanie el. na stos\n3.Usuniecie el. ze stosu\n4.Pobranie el. ze stosu\n5.Wyjscie\nWybor: ";
  28.     cin>>x;
  29.     switch(x){
  30. case 1:
  31.     if(top==NULL) cout<<endl<<"Stos jest pusty"<<endl;
  32.     else cout<<endl<<"Stos nie jest pusty"<<endl;
  33.     break;
  34. case 2:
  35.     push(&top);
  36.     break;
  37. case 3:
  38.     if(top==NULL) cout<<endl<<"Stos jest pusty"<<endl;
  39.     else {
  40.     usuwanie(&top);
  41.     }
  42.     break;
  43. case 4:
  44.     if(top==NULL) cout<<endl<<"Stos jest pusty"<<endl;
  45.     else {
  46.     wyswietlanie(top);
  47.     }
  48.     break;
  49. case 5:
  50.     br=false;
  51.     break;
  52.     }
  53.     }while(br==true);
  54.  
  55.  
  56.  
  57.     return 0;
  58. }
  59.  
  60. int generowanie(){
  61. srand(time(NULL));
  62. int liczba=rand()%(10)+1;
  63. return liczba;
  64. }
  65.  
  66. void push(stos**top){
  67. stos* nowyStos=new stos;
  68. nowyStos->liczba=generowanie();
  69. nowyStos->next=*top;
  70. *top=nowyStos;
  71. }
  72.  
  73. void wyswietlanie(stos*top){
  74. cout<<endl<<"Element na wierzchu:"<<top->liczba<<endl;
  75. }
  76.  
  77. void usuwanie(stos**top){
  78.     stos *temp= *top;
  79.     *top= (*top)->next;
  80.     delete temp;
  81. }
  82.