- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

The odd-even sword also known as the brick sort is a similar sorting technique, like bubble sort. This sorting technique is subdivided into 2 phases odd phase and even phase, Both these phases simultaneously at every iteration until all the elements get sorted.

The **Odd phase** of this programming technique works as a bubble sort but only on the elements that have an odd index.

Similarly, the **even phase** works only on the elements that have an even index.

For making this concept more clear let's take an example :

Input: a[]={3,5,7,6,1,4,2} Output: 1 2 3 4 5 6 7

The even-odd sort also known as brick sort, is a simple sorting technique that was designed keeping in mind parallel processing. It uses comparisons to sort its elements. the comparing takes place on all odd/even pair with their ages and elements. if any pair is in a wrong order then and the Order is switched to make it correct. this process goes on until the list gets sorted. as it was developed for parallel processes, it can awesome one value per processor and both the processes work concurrently on exchange-compare type operation. This algorithm was originally presented, and shown to be efficient on such processors

#include <stdio.h> #include <math.h> #define MAX 7 void swap(int *,int *); void oddeven_sort(int *); int main() { int a[]={3,5,7,6,1,4,2}, i; oddeven_sort(a); for (i = 0;i < MAX;i++) { printf(" %d", a[i]); } } void swap(int * x, int * y) { int temp; temp = *x; *x = *y; *y = temp; } void oddeven_sort(int * x) { int sort = 0, i; while (!sort) { sort = 1; for (i = 1;i < MAX;i += 2) { if (x[i] > x[i+1]) { swap(&x[i], &x[i+1]); sort = 0; } } for (i = 0;i < MAX - 1;i += 2) { if (x[i] > x[i + 1]) { swap(&x[i], &x[i + 1]); sort = 0; } } } }

1234567

- Related Questions & Answers
- C/C++ Program for Odd-Even Sort (Brick Sort)?
- Python Program for Odd-Even Sort / Brick Sort
- C++ Program for the Cocktail Sort?
- C++ Program for the Comb Sort?
- C++ Program for the Gnome Sort?
- C++ Program for Comb Sort?
- C++ Program for Gnome Sort?
- C++ Program for Cocktail Sort?
- C++ Program for Cycle Sort?
- C++ Program for Pigeonhole Sort?
- C Program for Selection Sort?
- C Program for Radix Sort
- Odd even sort in an array - JavaScript
- C++ Program for the Recursive Bubble Sort?
- C++ Program for Recursive Bubble Sort?

Advertisements