Advertisement
Stoycho_KK

Untitled

Oct 24th, 2022 (edited)
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. void evenOddSplit(std::vector<int>& arr) {
  2. for (size_t i = 1; i < arr.size(); i++) {
  3. int currentIndex = i - 1;
  4. int element = arr[i];
  5.  
  6. if(arr[i] % 2 == 1)
  7. continue;
  8.  
  9. while(currentIndex >= 0 && arr[currentIndex] % 2) {
  10. arr[currentIndex + 1] = arr[currentIndex];
  11. --currentIndex;
  12. }
  13.  
  14. ++currentIndex;
  15.  
  16. arr[currentIndex] = element;
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement