C program for Cocktail Sort algorithm | C code champ

C program for Cocktail Sort Algorithm : Cocktail sort is also known as bidirectional bubble sort, cocktail shaker sort, shaker sort (which can also refer to a variant of selection sort), ripple sort, shuffle sort, shuttle sort or happy hour sort, is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort. The algorithm differs from a bubble sort in that it sorts in both directions on each pass through the list. This sorting algorithm is marginally more difficult to implement in C than a bubble sort.

The difference between cocktail sort and bubble sort is 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. The result is that it has a slightly better performance than bubble sort, because it sorts in both directions. (Bubble sort can only move items backwards one step per iteration.)

Normally cocktail sort or shaker sort pass (one time in both directions) is counted as two bubble sort passes. In a typical implementation the cocktail sort is less than two times faster than a bubble sort implementation.

Let us see C how to write a C program for Cocktail sort which accepts numbers as input and generates the output sorted list.

Well, I am software programmer and love to code. My hobbies is to do Hacking, Coding, Blogging, Web Designing and playing online games.
Feel free to contact me at shiviskingg@gmail.com or lokesh@hackingloops.com