Advertisement
Guest User

Untitled

a guest
May 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using std::string;
  7.  
  8. auto main() -> int {
  9.     setlocale(LC_ALL, "polish");
  10.     srand(time(NULL));
  11.    
  12.     int usrCh = 0;
  13.    
  14.     const int tabSize = 7;
  15.     string choices[tabSize] = {
  16.         "Bubble sort",
  17.         "Quick sort",
  18.         "Counting sort",
  19.         "Insertion sort",
  20.         "Heapsort",
  21.         "Shell sort",
  22.         "Merge sort"
  23.     };
  24.    
  25.     for (int i = 0; i < tabSize; ++i)
  26.         std::cout << i+1 << ". " << choices[i] << std::endl;
  27.    
  28.     std::cout << "Twój wybór: ";
  29.         std::cin >> usrCh;
  30.    
  31.     switch(usrCh) {
  32.         case 1: {
  33.                 // bubble sort
  34.             int howMuch = 0;
  35.            
  36.             std::cout << "Ile liczb chcesz losować: ";
  37.                 std::cin >> howMuch;    
  38.             int tab[howMuch];  
  39.            
  40.             for (int i = 0; i < howMuch; ++i)  
  41.                 tab[i] = rand()%1000+1;    
  42.                
  43.             std::cout << "Wylosowane liczby to: " << std::endl;
  44.             for (int i = 0; i < howMuch; ++i)  
  45.                 std::cout << i+1 << ". " << tab[i] << std::endl;  
  46.                
  47.             // sortowanie
  48.             for (int i = 0; i < howMuch; ++i) {
  49.                 for (int j = 0; j < howMuch-1; ++j) {
  50.                     if (tab[j] > tab[j+1]) std::swap(tab[j], tab[j+1]);  
  51.                 }
  52.             }
  53.            
  54.             std::cout << "Posortowane liczby to: " << std::endl;
  55.             for (int i = 0; i < howMuch; ++i)
  56.                 std::cout << i+1 << ". " << tab[i] << std::endl;
  57.         }
  58.        
  59.         default: {
  60.             return 1;  
  61.         }
  62.     }
  63.    
  64.     return 0;  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement