Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <time.h>
- using namespace std;
- int main()
- {
- const int size = 10;
- int arr[size] = { 1,0,2,0,3,0,4,0,5,0 };
- int temp = 0;
- for (int i = size-1; i > 0; ) {
- if (arr[i] == 0 && arr[i-1] != 0)
- {
- temp = arr[i-1];
- arr[i-1] = arr[i];
- arr[i] = temp;
- i = size-1;
- continue;
- }
- else {
- i--;
- continue;
- }
- }
- for (int i = 0; i < size; i++) {
- cout << " " << arr[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment