A list of integers is sorted in “Wave” order if alternate items are not less than their immediate neighbors (thus the other alternate items are not greater than their immediate neighbors).

Thus, the array `[4, 1, 7, 5, 6, 2, 3]` is in **Wave** order because 4 >= 1, then 1 <= 7, then 7 >= 5, then 5 <= 6, then 6 >= 2, and finally 2 <= 3.

The wave-sorted lists has to begin with an element not less than the next, so `[1, 4, 5, 3]` is not sorted in Wave because 1 < 4

Your task is to implement a function that takes a list of integers and sorts it into wave order in place; your function shouldn't return anything.

Note:
- The resulting array shouldn't necessarily match anyone in the tests, a function just checks if the array is now wave sorted.

Source: codewars | Difficulty: EASY
Tags: Sorting

Data structures

Starter code: def wave_sort(a):
	

Solutions:
def wave_sort(a):
	a.sort()
	for i in range(1, len(a), 2):
		(a[i], a[i - 1]) = (a[i - 1], a[i])


def wave_sort(a):
	a.sort()
	last = len(a) - len(a) % 2
	(a[1::2], a[:last:2]) = (a[:last:2], a[1::2])


from itertools import chain

def wave_sort(a):
	for (i, x) in zip(chain(range(1, len(a), 2), range(0, len(a), 2)), sorted(a)):
		a[i] = x


def wave_sort(a):
	pivot = 0
	while pivot < len(a):
		max_val = max(a[pivot:])
		max_val_index = a[pivot:].index(max_val)
		tmp = a[pivot]
		a[pivot] = max_val
		a[max_val_index + pivot] = tmp
		pivot += 1
		if pivot < len(a):
			min_val = min(a[pivot:])
			min_val_index = a[pivot:].index(min_val)
			tmp = a[pivot]
			a[pivot] = min_val
			a[min_val_index + pivot] = tmp
			pivot += 1


def wave_sort(a):
	a.sort()
	(size, half) = (len(a), len(a) >> 1)
	for (low, high) in enumerate(range(0, size, 2), half):
		(a[low], a[high]) = (a[high], a[low])
	return a


def wave_sort(a):
	a.sort()
	[a.insert(i + 1, a.pop(i)) for i in range(len(a)) if i % 2 == 0]
	return


def wave_sort(a):
	(a1, a2) = (sorted(a), sorted(a)[::-1])
	for i in range(len(a)):
		if i % 2 == 1:
			a[i] = a1.pop(0)
		else:
			a[i] = a2.pop(0)
	print(a)
	return a


def wave_sort(a):
	a.sort()
	array = []
	length = len(a)
	if len(a) <= 1:
		return 0
	for x in range(0, length // 2, 1):
		array.append(a[length - 1 - x])
		array.append(a[x])
	if len(a) % 2 != 0:
		array.insert(length - 1, a[int(length / 2)])
	for x in range(0, length):
		a[x] = array[x]


def wave_sort(a):
	s = a[:]
	f = [max, min]
	for i in range(len(a)):
		v = f[i % 2](s)
		a[i] = v
		s.remove(v)