[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
Solved

# Cocktail Sorting help needed!

Posted on 2008-11-12
Medium Priority
1,129 Views
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
0
Question by:Dr_Billy
1 Comment

LVL 53

Accepted Solution

Infinity08 earned 500 total points
ID: 22948382
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
###### Suggested Courses
Course of the Month19 days, 18 hours left to enroll