AlgoDaily: Zeros to the end
Today's task was to push all the zeros of a list to the end without using an intermediate array.
I came up with a method that pops the list at the index where there is a zero and appends it to the end. Without a terminating condition, this goes into an infinite loop as the zeros get cycled back. So I made a counter that keeps track of the number of zeros and no longer does anything if the number of detected zeros is longer than the length of the list. That terminates the loop.
Here's the algorithm https://github.com/mariakesa/Algorithms/blob/master/AlgoDaily/AlgorithmsPractice.ipynb
Kommentaarid
Postita kommentaar