JosepRivaille

P98179: Inserció en una taula ordenada

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