Bubble-sort in Clojure... again
Following on from my previous solution to implementing the Bubble-sort algorithm in Clojure, I thought it would be interesting to experiment with a different approach. Taking advantage of lists and vectors respective cheap head and tail insertions, we can use these two properties to good effect as shown below.
reduce used previously with a concise recursive function you are able to see how the pass phase is complete - using a
changed flag to signal an alteration occurring within the iteration.
The implementation is again split up into a main and helper function which allows us to clearly see the separation between the conditional pass loop and bubble action.