shuffling array

I want to do the following:
lets suppose we have array a[]={1,2,3,4,0,0,0,0,0,0,0,0}
here the number of zeros are double of non zeros
so if a==1
then my array becomes a[]={1,0,2,0,3,0,4,0,0,0,0,0}
every non zero followed by zero and remaining zero at the end
similarly if b==1 the place two zero after every non zero..... help me just give me the idea I will be very thankful to u .
Last edited on
are you asking how to sort an array or how to shuffle it?
actually both :D but I want to get the output like above .
Scan the array once to figure out how many zeros are in it. Then work *backwards* to move the items to their proper locations.
Topic archived. No new replies allowed.