Advertisement
Felanpro

Sorting with vectors

Jul 19th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  8.  
  9. int main() {
  10.    
  11.     vector<int> v1{1, 6, 7, 2};
  12.     unsigned int x = 0;
  13.     unsigned int temp;
  14.    
  15.     for(x; x < v1.size(); x++)
  16.     {
  17.         for(int k = 0; k < v1.size(); k++)
  18.         {
  19.             if(v1[k] < v1[k + 1])
  20.             {
  21.                 temp = v1[k];
  22.                 v1[k] = v1[k + 1];
  23.                 v1[k + 1] = temp;
  24.             }
  25.         }
  26.     }
  27.    
  28.     for(int c = 0; c < v1.size(); c++)
  29.     {
  30.         cout << v1[c] << endl;
  31.     }
  32.    
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement