Online Course Discussion Forum

By the 2 direction bubble sort, do you mean the cocktail sort?

 
 
LensmireJohn的头像
Re: By the 2 direction bubble sort, do you mean the cocktail sort?
LensmireJohn - 2020年06月26日 Friday 12:29
 

Hi Joseph. I'd rather not worry about specific names, so as an example, if we had the list$$[A, B, C, D, E, F, G, H]$$a normal bubble sort would start by comparing positions $A,B$ then positions $B,C$, etc. up to positions $G,H$ and then continue back at the start with $A,B$ again.

For a two direction bubble sort, it starts the same, $A,B$, then $B,C$ up to $G,H$, but then reverses and works it's way back "down" the list, comparing $F,G$, then, $E,F$, etc.

To summarize, a regular bubble sort keeps looping through list in the same direction ("up" over and over) while the two direction swaps after each pass ("up", "down", "up", "down", etc.)

Hope this helps!