informaticage

Bubble sort

Sep 14th, 2014 (edited)
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #define MAX 100
  3. using namespace std;
  4.  
  5. int main(int argc, char *argv[])
  6. {  
  7.     int n, swap;
  8.     int vet[MAX];
  9.     cout << "Inserire n vet_(max = 100): " << endl;
  10.     do{
  11.         cin >> n;
  12.     }while(n > 100);
  13.     for (int i = 0; i < n; i++){
  14.         cout << "Vet" << i + 1 << " ";
  15.         cin >> vet[i];
  16.     }
  17.     for(int i = 0; i < n; i++){
  18.         for(int j = 0; j < n; j++){
  19.             if(vet[j] < vet [i]){
  20.                 swap = vet[i];
  21.                 vet[i] = vet[j];
  22.                 vet[j] = swap;
  23.             }
  24.         }
  25.     }
  26.     cout << endl;
  27.     for (int i = 0; i < n; i++){
  28.         cout << vet[i] << " ";
  29.     }
  30.  
  31.     return 0;
  32. }
Add Comment
Please, Sign In to add comment