Facebook
From Denim Dormouse, 3 Years ago, written in Plain Text.
This paste is a reply to Untitled from Buff Macaw - view diff
Embed
Download Paste or View Raw
Hits: 200
  1. #include <iostream>
  2. #include <time.h>
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <cstdlib>
  6. #include <conio.h>
  7. using namespace std;
  8. int dane[6];
  9. int rozmiar;
  10.  
  11. void wyswietl_stos()
  12. {
  13.     system("CLS");
  14.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),14);
  15.     cout<<endl;
  16.     cout<<"----------------"<<endl;
  17.     cout<<"ZAWARTOSC STOSU:"<<endl;
  18.     cout<<"----------------"<<endl;
  19.     for (int i=rozmiar; i>=1; i--)
  20.     {
  21.         cout<<dane[i]<<endl;
  22.     }
  23.  
  24.     if (rozmiar==0)
  25.         cout<<"pusty"<<endl;
  26.  
  27.     cout << "----------------"<<endl<<endl;
  28.  
  29.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15);
  30. }
  31. //------------------------------------------------------------------------
  32. void push()
  33. {
  34.     if (rozmiar>=5)
  35.     {
  36.         cout << "Stos pelny!";
  37.         Sleep(1000);
  38.     }
  39.     else
  40.     {
  41.         cout<<endl<< "PUSH (jaka liczbe polozyc na stosie): ";
  42.  
  43.         rozmiar=rozmiar+1;
  44.         cin>>dane[rozmiar];
  45.     }
  46. }
  47. //------------------------------------------------------------------------
  48. void pop()
  49. {
  50.     if (rozmiar>=1)
  51.     {
  52.         cout<<endl<<"POP - nastapi usuniecie ze stosu liczby: "<<dane[rozmiar];
  53.         Sleep(2000);
  54.  
  55.         rozmiar=rozmiar-1;
  56.     }
  57.     else
  58.     {
  59.         cout << "Stos pusty!";
  60.         Sleep(1000);
  61.     }
  62. }
  63. //------------------------------------------------------------------------
  64. void size()
  65. {
  66.     cout<<endl<<"Liczba elementow na stosie: "<<rozmiar;
  67.     Sleep(2000);
  68. }
  69. //------------------------------------------------------------------------
  70. void empty()
  71. {
  72.  
  73.     if (rozmiar==0)
  74.         cout<<endl<<"EMPTY (stos pusty?) ->  TRUE";
  75.     else
  76.         cout<<endl<<"EMPTY (stos pusty?) ->  FALSE";
  77.     Sleep(2000);
  78. }
  79. //------------------------------------------------------------------------
  80. void quicksort(int *tablica, int lewy, int prawy)
  81. {
  82.     int piwot=tablica[(lewy+prawy)/2];
  83.     cout<<"wartosc piwota "<<piwot<<endl;
  84.     int i,j,x;
  85.     i=lewy;// 0
  86.     j=prawy;// 6
  87.     do         // 3 65 1 43 45 4
  88.     {
  89.         while (tablica[i]<piwot)
  90.             i++; //0
  91.         while (tablica[j]>piwot)
  92.             j--; //0
  93.         if (i<=j)
  94.         {
  95.             x=tablica[i];
  96.             tablica[i]=tablica[j];
  97.             tablica[j]=x;
  98.             i++; // 1
  99.             j--;// -1
  100.             cout<<"to Jest i "<<i-1<<"to Jest J "<<j-1<<endl;
  101.             cout<<"to jest wartość i "<<tablica[i]<<"to jest wartość j "<<tablica[j]<<endl;
  102.                    }
  103.     }
  104.     while(i<=j);
  105.     if(j>lewy)
  106.         quicksort(tablica,lewy, j);
  107.     if(i<prawy)
  108.         quicksort(tablica, i, prawy); //rekurencja funcki z intencj¹ zmiany pivota
  109. }
  110. void losowanko()
  111. {
  112.     int ile;
  113.     system("CLS");
  114.     srand(time(NULL)); // "inicjowanie losowania"
  115.     cout<<"Podaj ile liczb ma byc posortowanych:  ";
  116.     cin>>ile;
  117.     int *tablica;
  118.     tablica= new int[ile];
  119.     for(int i=0; i<ile; i++)
  120.     {
  121.         tablica[i]=rand()%100+1;//losowanie liczby od 1 do 100 i wpisywanie jej do tablicy
  122.         cout<<tablica[i]<<"  ";
  123.     }
  124.     cout<<endl<<"";
  125.     cout<<"Liczby po sortowaniu:   "<<endl;
  126.     quicksort(tablica, 0, ile-1); //wywo³anie funcki
  127.     for(int i=0; i<ile; i++)
  128.     {
  129.         cout<<tablica[i]<<"  ";
  130.     }
  131.     cout<<endl<<" ";
  132.     delete [] tablica;
  133.     cout<<"ENTER POWROT DO MENU"<<endl;
  134.     getchar();
  135.     getchar();
  136. }
  137. void menu_stosu()
  138. {
  139.     int wybor;
  140.     rozmiar=0;
  141.     do
  142.     {
  143.         wyswietl_stos();
  144.         cout << "MENU GLOWNE STOSU:"<<endl;
  145.         cout << "------------------------------------------"<<endl;
  146.         cout << "1. PUSH (dodaje element na szczyt stosu) "<<endl;
  147.         cout << "2. POP (usuwa element ze szczytu stosu) "<<endl;
  148.         cout << "3. SIZE (ile elementow na stosie) "<<endl;
  149.         cout << "4. EMPTY (czy stos jest pusty?) "<<endl;
  150.         cout << "5. Powrucenie do menu "<<endl;
  151.         cout << "------------------------------------------"<<endl;
  152.         cout << "Wybor: ";
  153.         cin >> wybor;
  154.         switch (wybor)
  155.         {
  156.         case 1:
  157.             push();
  158.             break;
  159.  
  160.         case 2:
  161.             pop();
  162.             break;
  163.  
  164.         case 3:
  165.             size();
  166.             break;
  167.  
  168.         case 4:
  169.             empty();
  170.             break;
  171.         }
  172.     }
  173.     while (wybor != 5);
  174. }
  175.  
  176.  
  177. int main()
  178. {
  179.     char wybur;
  180.     do
  181.     {
  182.         system("CLS");
  183.         cout << "MENU GLOWNE PROGRAMU:"<<endl;
  184.         cout << "------------------------------------------"<<endl;
  185.         cout << "1. Sortowanie liczb "<<endl;
  186.         cout << "2. Stos "<<endl;
  187.         cout << "3. Koniec programu "<<endl;
  188.         cout << "------------------------------------------"<<endl;
  189.         wybur=getch();
  190.         switch (wybur)
  191.         {
  192.         case '1':
  193.         {
  194.             losowanko();
  195.         }
  196.         break;
  197.  
  198.         case '2':
  199.         {
  200.             menu_stosu();
  201.         }
  202.         break;
  203.         }
  204.     }
  205.     while(wybur !='3');
  206.     return 0;
  207. }
  208.  

Replies to Re: Untitled rss

Title Name Language When
Re: Re: Untitled Abrupt Hog text 3 Years ago.