Advertisement
Tannenfels

Untitled

Jul 13th, 2022
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4. #define ARRAY_SIZE 10000
  5.  
  6. using namespace std;
  7.  
  8. void fill_random(int*a)
  9. {
  10.     for(int i=0;i<ARRAY_SIZE;i++)
  11.     {
  12.         a[i]=rand();
  13.     }
  14. }
  15.  
  16. void swap(int* xp, int* yp)
  17. {
  18.     int temp = *xp;
  19.     *xp = *yp;
  20.     *yp = temp;
  21. }
  22.  
  23. void slowSort(int A[], int i, int j = ARRAY_SIZE)
  24. {
  25.     if (i >= j)
  26.         return;
  27.  
  28.     int m = (i + j) / 2;
  29.     slowSort(A, i, m);
  30.     slowSort(A, m + 1, j);
  31.  
  32.     if (A[j] < A[m]) {
  33.         swap(&A[j], &A[m]);
  34.     }
  35.  
  36.     slowSort(A, i, j - 1);
  37. }
  38.  
  39.  
  40. void printArray(int arr[])
  41. {
  42.     int i;
  43.     for (i = 0; i < ARRAY_SIZE; i++)
  44.         cout << arr[i] << " ";
  45.     cout << endl;
  46. }
  47.  
  48.  
  49. int main()
  50. {
  51.     vector<wchar_t*> v;
  52.     int*arr=(int*)malloc(ARRAY_SIZE*sizeof(int));
  53.     fill_random(arr);
  54.     slowSort(arr, 0, ARRAY_SIZE - 1);
  55.     printArray(arr);
  56.  
  57.     return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement