Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: move all 0s in an array to the beginning keeping other elements order same

by Cristoforo (Curate)
on May 02, 2014 at 00:07 UTC ( [id://1084714]=note: print w/replies, xml ) Need Help??


in reply to move all 0s in an array to the beginning keeping other elements order same

Another way that works!
my @array = (1, 2, 3, 4, 2, 1, 2, 0, 1, 0, 0); for my $i (0 .. $#array) { unshift @array, splice @array, $i, 1 if $array[$i] == 0; }
  • Comment on Re: move all 0s in an array to the beginning keeping other elements order same
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1084714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-18 22:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found