Cocktail Sorting help needed!

Posted on 2008-11-12
Last Modified: 2012-06-22
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
Question by:Dr_Billy
    1 Comment
    LVL 53

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now