JosepRivaille

P81602: Ordenació per selecció

May 23rd, 2015
1,410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. void ordena_per_seleccio(vector<double>& v, int m) {
  7.     if (m > 0) {
  8.         double max = v[0];
  9.         int pos = 0;
  10.         for (int i = 1; i <= m; ++i) {
  11.             if (v[i] > max) {
  12.                 max = v[i];
  13.                 pos = i;
  14.             }
  15.         }
  16.         v[pos] = v[m];
  17.         v[m] = max;
  18.         return ordena_per_seleccio(v, m-1);
  19.     }
  20. }
  21.  
  22. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment