Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int w;
  8. int *tab = new int[w];
  9. void generowanie_tablicy(int w, int *tab);
  10. void wyswietlenie_tablicy(int w, int *tab);
  11. void sortowanie_babelkowe(int w, int *tab);
  12. void sortowanie_przez_wstawianie(int w, int *tab);
  13.  
  14. int main()
  15. {
  16. bool menu=true;
  17.     cout << "^^^^^^^^Budowanie tablicy^^^^^^^^^" << endl << endl;
  18.     int w, metoda;
  19.     cout << endl << endl << "Podaj liczbe elementow tablicy: ";
  20.     cin >> w;
  21.     generowanie_tablicy(w, tab);
  22.     cout << "^^^^^^^^Tabela losowych liczb zostala utworzona^^^^^^^^" << endl << endl;
  23.     system("PAUSE");
  24.     system("CLS");
  25. while(menu)
  26. {
  27.     cout << endl << "Wybierz co chcesz zrobic:" << endl << endl;
  28.     cout << "1- wyswietlenie tabeli losowych liczb" << endl;
  29.     cout << "2- dodawanie elementu na koniec" << endl;
  30.     cout << "3- sortowanie babelkowe" << endl;
  31.     cout << "4- sortowanie mieszane" << endl;
  32.     cout << "5- sortowanie przez wybor" << endl;
  33.     cout << "6- sortowanie przez proste wstawianie" << endl;
  34.     cout << "7- sortowanie przez binarne wstawianie" << endl;
  35.     cout << "8- wypisywanie tablicy po 10 elementow" << endl << endl;
  36. cout << "9- zakonczenie programu"<<endl;
  37.     cin >> metoda;
  38.    
  39.     switch (metoda)
  40.     {
  41.     case 1: system("CLS"); wyswietlenie_tablicy(w, tab); break;
  42.     case 2: system("CLS");  break;
  43.     case 3: system("CLS"); wyswietlenie_tablicy(w, tab); sortowanie_babelkowe(w, tab); break;
  44.     case 4: system("CLS"); cout << "4- sortowanie mieszane"; break;
  45.     case 5: system("CLS"); cout << "5- sortowanie przez wybor"; break;
  46.     case 6: system("CLS"); wyswietlenie_tablicy(w, tab); sortowanie_przez_wstawianie(w, tab); break;
  47.     case 7: system("CLS"); cout << "7- sortowanie przez binarne wstawianie"; break;
  48.     case 8: system("CLS"); cout << "8- wypisywanie tablicy po 10 elementow"; break;
  49.   case 9:menu=false; break;
  50.     default: system("CLS"); cout << "Blednie wybrales - ponow probe z zakresu 1-8"; ; break;
  51.     }
  52. }
  53.  
  54. getchar();
  55. cin.ignore();
  56. return 0;
  57. }
  58.  
  59.  
  60.  
  61. void generowanie_tablicy(int w, int *tab)
  62. {
  63.     for (int i = 0; i<w; i++)
  64.     {
  65.         tab[i] = rand() % 99 - 0;
  66.     }
  67.     cout << endl << endl;
  68. }
  69.  
  70. void wyswietlenie_tablicy(int w, int *tab)
  71. {
  72.     cout << "^^^^^^^^tabela losowych liczb^^^^^^^^" << endl << endl;
  73.     for (int i = 0; i<w; i++)
  74.     {
  75.         cout << setw(4) << tab[i];
  76.     }
  77.     cout << endl << endl;
  78. }
  79.  
  80. void sortowanie_babelkowe(int w, int *tab)
  81. {
  82.     cout << "^^^^^^^^tabela po sortowaniu babelkowym^^^^^^^^" << endl << endl;
  83.     for (int i = 0; i < w; i++)
  84.     {
  85.         for (int j = 0; j<w - i - 1; j++)
  86.             if (tab[j]>tab[j + 1])
  87.             {
  88.                 int z = tab[j];
  89.                 tab[j] = tab[j + 1];
  90.                 tab[j + 1] = z;
  91.             }
  92.     }
  93.     for (int i = 0; i < w; i++)
  94.     {
  95.         cout << setw(4) << tab[i];
  96.     }
  97. }
  98.  
  99. void sortowanie_przez_wstawianie(int w, int *tab)
  100. {
  101.     cout << "^^^^^^^^tabela po sortowaniu przez proste wstawianie^^^^^^^^" << endl << endl;
  102.     for (int i = w - 2; i >= 0; i--)
  103.     {
  104.         int z = tab[i];
  105.         int j = i + 1;
  106.  
  107.  
  108.         while ((j<w) && (z>tab[j]))
  109.         {
  110.             tab[j - 1] = tab[j];
  111.             j++;
  112.         }
  113.  
  114.         tab[j - 1] = z;
  115.     }
  116.     for (int i = 0; i<w; i++)
  117.  
  118.         cout << setw(4) <<tab[i];
  119.     cout << endl << endl << "Sortowanie przez wstawianie polega na wstawiamu" << endl << "liczby w odpowiednie miejsce przesuwajac pozostaee, nastepna"
  120.          << endl << "takze wstawiamy miedzy odpowiednie karty i tak ukladamy zestaw" << endl << "liczb.Sorotwanie to jest podobne do ukladania kart.";
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement