odd even sort Algorithm

The odd-even sort algorithm, also known as the brick sort algorithm, is a simple and relatively inefficient comparison-based sorting technique that works by repeatedly comparing and swapping adjacent pairs of elements in an array, with the goal of sorting it in ascending or descending order. The algorithm gets its name from the two distinct phases it undergoes during each iteration: an "odd" phase and an "even" phase. In the odd phase, the algorithm compares and swaps elements at odd indices with their adjacent elements at even indices; similarly, in the even phase, it compares and swaps elements at even indices with their adjacent elements at odd indices. The algorithm continues to alternate between these two phases until the entire array is sorted. Despite its simplicity, the odd-even sort algorithm is not widely used in practice due to its poor performance in comparison to more efficient sorting algorithms such as quicksort and merge sort. The worst-case and average-case time complexity of the odd-even sort is O(n^2), where n is the number of elements in the array, which makes it undesirable for large datasets. However, the algorithm can be useful in parallel processing environments, as it can be easily adapted to work with multiple processors, each handling different portions of the array. In such cases, the odd-even sort can achieve a time complexity of O(n) under ideal conditions, making it a viable option for certain parallel computing applications.
package main

/*
 * Odd-Even sort - https://en.wikipedia.org/wiki/Odd-even_sort
 */

func OddEvenSort(arr []int) {
	tmp, isSorted := 0, false

	for isSorted == false {

		isSorted = true

		for i := 1; i < len(arr) - 1; i = i + 2 {
			if arr[i] > arr[i + 1] {
				tmp = arr[i]
				arr[i] = arr[i + 1]
				arr[i + 1] = tmp

				isSorted = false
			}
		}

		for i := 0; i < len(arr) - 1; i = i + 2 {
			if arr[i] > arr[i + 1] {
				tmp = arr[i]
				arr[i] = arr[i + 1]
				arr[i + 1] = tmp

				isSorted = false
			}
		}
	}
}

LANGUAGE:

DARK MODE: