Skip to content

Commit

Permalink
Create move_all.cpp
Browse files Browse the repository at this point in the history
Signed-off-by: Akash <[email protected]>
  • Loading branch information
Akash1437 committed Oct 17, 2022
1 parent 8a5697d commit 9ed70f1
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions move_all.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
using namespace std;
void moveZeroesToEnd(int arr[], int n) {
int index = 0;
for (int i = 0; i < n; i++) {
if (arr[i] != 0) {
arr[index++] = arr[i];
}
}
while (index < n) {
arr[index++] = 0;
}
}
int main() {
int arr[] = {4, 5, 0, 3, 2, 0, 0, 0, 5, 0, 1};
int n = 11;
moveZeroesToEnd(arr, n);
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}

0 comments on commit 9ed70f1

Please sign in to comment.