sorting/Odd-Even Sort.cpp
// A function to sort the algorithm using Odd Even sort 
A function to sort the algorithm using Odd Even sort
A function to sort the algorithm using Odd Even sort
void oddEvenSort(int arr[], int n) 
{ 
	bool isSorted = false; 
	while (!isSorted) 
	{ 
		isSorted = true; 
		for (int i=1; i<=n-2; i=i+2) 
		{ 
			if (arr[i] > arr[i+1]) 
			{ 
				swap(arr[i], arr[i+1]); 
				isSorted = false; 
			} 
		} 
		for (int i=0; i<=n-2; i=i+2) 
		{ 
			if (arr[i] > arr[i+1]) 
			{ 
				swap(arr[i], arr[i+1]); 
				isSorted = false; 
			} 
		} 
	} 
	return; 
}
void oddEvenSort ( int arr [ ] , int n ) { bool isSorted = false ; while ( ! isSorted ) { isSorted = true ; for ( int i = 1 ; i <= n - 2 ; i = i + 2 ) { if ( arr [ i ] > arr [ i + 1 ] ) { swap ( arr [ i ] , arr [ i + 1 ] ) ; isSorted = false ; } } for ( int i = 0 ; i <= n - 2 ; i = i + 2 ) { if ( arr [ i ] > arr [ i + 1 ] ) { swap ( arr [ i ] , arr [ i + 1 ] ) ; isSorted = false ; } } } return ; }
A function to sort the algorithm using Odd Even sort
A function to sort the algorithm using Odd Even sort
// Initially array is unsorted  // Perform Bubble sort on odd indexed element  // Perform Bubble sort on even indexed element 