简体   繁体   中英

Which sorting algorithm is this?

I need to know which sorting algorithm sorts like this:

[4 1 7 6 3 11]

[4 1 7 3 6 11]

[4 1 3 7 6 11]

[1 4 3 7 6 11]

[1 4 3 6 7 11]

[1 3 4 6 7 11]

Tomorrow is exam, and I'm confused. It shall be a simple algorithm, but it can't be insertion sort / selection sort, i even looked at heapsort (absolutely) and merge sort - last option.

I would say it's mergesort, but with the addition it should be easy, I'm unsure. Or i heavily misunderstood how the algorithms work. :(

Thanks for reading, at least! :)

As you can see, the algorithm works by comparing two adjacent values, which makes it a Bubble Sort , however the interesting thing to note here is that instead of the sorting being done in left to right passes, it seems to be doing them in passes from right to left; which in turn makes this a Reversed Bubble Sort .

It is a Bubble sort algorithm that starts from the right or your array. What it does (besides being horribly slow) is to compare the neighbors from right to left. as soon it finds two neighbors that are in the wrong order, it switches them. IN the next round the algorithm starts again from the right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM