Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstring>
  5. #include <iomanip>
  6. #include <cmath>
  7. #include <cstdlib>
  8. #include <stdio.h>
  9. #include <conio.h>
  10. #include <algorithm>
  11. #include <ctime>
  12. #define jump 100000
  13. #define qty 10
  14.  
  15. using namespace std;
  16.  
  17. void display(int size, int *nrs)
  18. {
  19.     system("cls");
  20.     for (int i = 0; i < size; i++)
  21.     {
  22.         cout << *nrs << " ";
  23.         nrs++;
  24.     }
  25.     cout << endl;
  26.     system("pause");
  27.     return;
  28. }
  29.  
  30. void IS(int size, int *nrs) //Insertion sort
  31. {
  32.     return;
  33. }
  34.  
  35. void SS(int size, int *nrs) //Selection sort
  36. {
  37.     return;
  38. }
  39.  
  40. void BS(int size, int *nrs) //Bubble sort xD
  41. {
  42.     for (int i = 0; i < size; i++)
  43.     {
  44.         if (size > 50000) break;
  45.         for (int j = 0; j < (size - i - 1); j++)
  46.         {
  47.             if (nrs[j] > nrs[j + 1]) swap(nrs[j], nrs[j + 1]);
  48.         }
  49.     }
  50.     return;
  51. }
  52.  
  53. void HS(int size, int *nrs) //Heap sort
  54. {
  55.     return;
  56. }
  57.  
  58. void QS(int size, int *nrs) //Quick sort
  59. {
  60.     return;
  61. }
  62.  
  63. void MS(int size, int *nrs) //Merge sort
  64. {
  65.     return;
  66. }
  67.  
  68. void ShS(int size, int *nrs) //Shell sort
  69. {
  70.     return;
  71. }
  72.  
  73. void CS(int size, int *nrs) //Counting sort
  74. {  
  75.     int* hold = new int [size];
  76.     int* nrs_sorted = new int [size];
  77.    
  78.     for(int i = 0; i < size; ++i) hold[i] = 0;
  79.  
  80.     for(int i = 0; i < size; ++i) ++hold[nrs[i]];
  81.    
  82.     for(int i = 1; i < size; ++i) hold[i] += hold[i-1];
  83.    
  84.     for(int i = size - 1; i >= 0; --i) nrs_sorted[--hold[nrs[i]]] = nrs[i];
  85.    
  86.     delete [] hold;
  87.     delete [] nrs_sorted;
  88.      
  89.     return;
  90. }
  91.  
  92. void to_file()
  93. {
  94.     ex1 << "CHUJ";
  95. }
  96.  
  97. void exercise1()
  98. {
  99.     system("pause");
  100.     system("cls");
  101.    
  102.     ofstream ex1; ex1.open("Zadanie_1.txt");
  103.     ex1 << left << setw(15) << "SoRtInG" << "BS:    " << "HS:   " << "CS:   " << "ShS:" << endl << endl;
  104.    
  105.     for (int i = jump; i < (qty * jump) + 1; i += jump)
  106.     {
  107.         cout << left << setw(15) << i;
  108.        
  109.         int* nrs = new int [i];
  110.        
  111.         for (int j = 0; j < i; j++) nrs[j] = rand() % i;
  112.        
  113.         clock_t start, stop;
  114.         double time;
  115.        
  116.         start = clock();
  117.         BS(i, nrs);
  118.         stop = clock();
  119.         cout << "   " << (double (stop - start)) / CLOCKS_PER_SEC << "  ";
  120.         ex1 << left << setw(15) << i << (double (stop - start)) / CLOCKS_PER_SEC;
  121.        
  122.         start = clock();
  123.         HS(i, nrs);
  124.         stop = clock();
  125.         cout << "   " << (double (stop - start)) / CLOCKS_PER_SEC << "  ";
  126.         ex1 << "    " << (double (stop - start)) / CLOCKS_PER_SEC;
  127.        
  128.         start = clock();
  129.         CS(i, nrs);
  130.         stop = clock();
  131.         cout << "   " << (double (stop - start)) / CLOCKS_PER_SEC << "  ";
  132.         ex1 << "    " << (double (stop - start)) / CLOCKS_PER_SEC;
  133.        
  134.         start = clock();
  135.         ShS(i, nrs);
  136.         stop = clock();
  137.         cout << "   " << (double (stop - start)) / CLOCKS_PER_SEC << endl;
  138.         ex1 << "    " << (double (stop - start)) / CLOCKS_PER_SEC << endl;
  139.        
  140.         delete [] nrs;
  141.     }
  142.    
  143.     ex1.close();
  144.     ex1.clear();
  145.     return;
  146. }
  147.  
  148. void exercise2()
  149. {
  150.     return;
  151. }
  152.  
  153. int main()
  154. {
  155.     exercise1();
  156.     //exercise2();
  157.     return 0;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement