Write a C program for odd-even sort or brick sort. An Odd-Even Sort or brick sort is a simple sorting algorithm. In this algorithm we compare all odd/even indexed pairs of adjacent elements in the list and, if a pair is in the wrong order the elements are switched. The next step repeats this for even/odd indexed pairs. Then it alternates between odd/even and even/odd steps until the list is sorted.

C program for odd-even sort or brick sort

  • Save above program as oddeven.c
  • Compile using gcc and run to see output.

complexity of above implementation

Auxiliary Space: O(n)
The best case Time Complexity: O(n) and in worst case it would be O(n²)

Wikipedia has given c++ implementation as below

The odd-even sort or brick sort is just like bubble sort.

Note: It is our recommendation for readers that provide us any other good information.

Ref:

https://en.wikipedia.org/wiki/Odd%E2%80%93even_sort




Related Contents to follow