Skip to content

Commit

Permalink
Move Zeroes
Browse files Browse the repository at this point in the history
This is the code in C++ to "Move The Zeroes Of An Array to the End".
  • Loading branch information
ankurgupta255 committed Oct 28, 2018
1 parent 2268063 commit bed7db9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Algorithms/Array/Move Zeroes to The End.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<iostream>
using namespace std;
int main()
{
int n;
int a[100];
int i=0;
int j=n-1;
int cnt=0;
cout<<"Enter the size of the array: ";
cin>>n;
cout<<"Enter the array Elements: ";
for(int i=0;i<n;i++){
cin>>a[i];
}
for(i=0;i<n;i++){
if(a[i]==0){
cnt++;
}
}
for(i=0;i<n-cnt;i++){
if(a[i]==0){
for(j=n-1;j>=0;j--){
if(a[j]!=0){
int temp=a[i];
a[i]=a[j];
a[j]=temp;
break;
}
else{
cout<<"All Elements are 0s.";
}}}}
for(i=0;i<n;i++){
cout<<a[i]<<"\t";
}
return 0;
system("PAUSE");
}

0 comments on commit bed7db9

Please sign in to comment.