Advertisement
csansoon

P10.03 P98179 Insertion into a sorted table

Dec 23rd, 2018
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. void insert(vector<double>& v) {
  7.         int siz = v.size();
  8.         for (int i = 1; i < siz; ++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. // (c) Carlos Sansón (Best pro1 delegate ever for sure) @csansoon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement