Advertisement
Jayss8

WCIPEG Sorting (C++)

Jul 6th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     int a, b, c;
  9.     int i[32000];
  10.  
  11.     cin >> n;
  12.  
  13.     for (a = 0; a < n; a++)
  14.     {
  15.         cin >> i[a];
  16.     }
  17.  
  18.     for (a = 1; a < n; a++)
  19.     {
  20.         c = a;
  21.         while (i[c] < i[c - 1] && c >= 1)
  22.         {
  23.             b = i[c];
  24.             i[c] = i[c - 1];
  25.             i[c - 1] = b;
  26.             c--;
  27.         }
  28.     }
  29.  
  30.     for (a = 0; a < n; a++)
  31.     {
  32.         cout << i[a] << endl;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement