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

Thanks

 
P.S  am not the primary holder of this account
LVL 7
Dr_BillyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
Well, here's some pseudo-code for the cocktail sort algorithm :

        http://en.wikipedia.org/wiki/Cocktail_sort#Pseudocode

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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Assembly

From novice to tech pro — start learning today.