Advertisement
michelksu

Untitled

Jul 11th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void des_sort(int my_array[], int array_size) {
  7.     for (int p = 1; p <= array_size - 3; p++) {
  8.         for (int i = 0; i < array_size - 1; i++) {
  9.             int &current_el = my_array[i];
  10.             int &next_el = my_array[i + 1];
  11.  
  12.             if (current_el < next_el) {
  13.                 int temp = current_el;
  14.                 current_el = next_el;
  15.                 next_el = temp;
  16.             }
  17.         }
  18.     }
  19. }
  20.  
  21. void print_array(int my_array[], int array_size) {
  22.     for (int i = 0; i < array_size; i++)
  23.         cout << my_array[i] << " ";
  24.     cout << endl;
  25. }
  26.  
  27. int main()
  28. {
  29.     int array_size = 17;
  30.     int my_array[] = { 1, 2, 3, 4, 4, 6, 7, 8, 9, 10, 88, 23, 19, 4, 5, 6, 7 };
  31.  
  32.     des_sort(my_array, array_size);
  33.  
  34.     print_array(my_array, array_size);
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement