diptangsu / Sorting-Algorithms

Swapping can be done using parallel assignment CRT-A0009
Anti-pattern
Major
3 years ago4 years old
can re-write as arr[0], arr[i] = arr[i], arr[0]
26	}
27
28	for i := n - 1; i >= 0; i-- {
29		tmp := arr[0]30		arr[0] = arr[i]
31		arr[i] = tmp
32		heapify(arr, 0, i)
can re-write as arr[i], arr[max] = arr[max], arr[i]
45		max = r
46	}
47	if i != max {
48		tmp := arr[i]49		arr[i] = arr[max]
50		arr[max] = tmp
51		heapify(arr, max, n)
can re-write as arr[j], arr[j+1] = arr[j+1], arr[j]
25		flag := false
26		for j := 0; j < n - i - 1; j++ {
27			if arr[j] > arr[j + 1] {
28				tmp := arr[j]29				arr[j] = arr[j + 1];
30				arr[j + 1] = tmp
31				flag = true
can re-write as tosort[i], tosort[i-1] = tosort[i-1], tosort[i]
37
38		for i := end; i > 0; i-- {
39			if tosort[i] < tosort[i-1] {
40				temp := tosort[i]41				tosort[i] = tosort[i-1]
42				tosort[i-1] = temp
43				flag = 1
can re-write as tosort[i], tosort[i+1] = tosort[i+1], tosort[i]
23		for i := 0; i <end; i++ {
24			// fmt.Println(tosort[i])
25			if tosort[i] > tosort[i+1] {
26				temp := tosort[i]27				tosort[i] = tosort[i+1]
28				tosort[i+1] = temp
29				flag = 1