Skip to content

Instantly share code, notes, and snippets.

@anil477
Created June 19, 2017 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anil477/bd2db8c959855ab831e9edd511a259ab to your computer and use it in GitHub Desktop.
Save anil477/bd2db8c959855ab831e9edd511a259ab to your computer and use it in GitHub Desktop.
Move all zeroes to end of array
// http://www.geeksforgeeks.org/move-zeroes-end-array/
// Input : arr[] = {1, 2, 0, 0, 0, 3, 6};
// Output : arr[] = {1, 2, 3, 6, 0, 0, 0};
count = 0;
for(i=0; i<n ;i++)
{
if(a[i]!=0)
{
a[count] = a[i];
count++;
}
}
while(count<n){
a[count] = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment