Cocktail Sorting help needed!

I need to know how to do the Cocktail sorting in assembly (used to sort arrays)

Am using Virgo to emulator 8086 machine

this is the  description i was given


Cocktail sort is a slight variation of bubble sort. It differs in that instead of repeatedly passing through the list from bottom to top, it passes alternately from bottom to top and then from top to bottom. It can achieve slightly better performance than a standard bubble sort. The reason for this is that bubble sort only passes through the list in one direction and therefore can only move items backward one step at each iteration.
An example of a list that proves this point is the list (2,3,4,5,1), which would only need to go through one pass of cocktail sort to become sorted, but if using an ascending bubble sort would take four passes. However one cocktail sort pass should be counted as two bubble sort passes. Typically cocktail sort is less than two times faster than bubble sort.


I've searched in google and to be honest i did not get it or at least am not sure what i understand is what they mean

i would like to know how come it's going to go through the array once only

and if no body know's how to do it in assembly i hope i got the way in c++ or php at least


P.S  am not the primary holder of this account
Who is Participating?
Infinity08Connect With a Mentor Commented:
Well, here's some pseudo-code for the cocktail sort algorithm :

I'm sure you can implement it in any language you like :)

>> i would like to know how come it's going to go through the array once only

cocktail sort will pass over the array (2,3,4,5,1) from left to right, swapping nothing except the last two elements to get (2,3,4,1,5), and will then turn back from right to left, moving the 1 all the way to the left to get (1,2,3,4,5), which is fully sorted. The algorithm stops there since no more swaps are done after that.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.