Skip to content

Commit 67909ef

Browse files
committed
[fix] code format for quick-sort
1 parent 72a1a81 commit 67909ef

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

quick-sort/quick-sort.go

+15-16
Original file line numberDiff line numberDiff line change
@@ -9,51 +9,50 @@ package main
99

1010
import "fmt"
1111

12-
13-
func Swap(a *int, b *int){
12+
func Swap(a *int, b *int) {
1413
t := *a
1514
*a = *b
1615
*b = t
1716
}
1817

1918
func Partition(arr []int, start, end int) int {
20-
19+
2120
pivot := arr[end]
2221

2322
//Index of smaller element
2423
var i int = (start - 1)
2524

26-
for j := start; j <= end - 1; j++ {
25+
for j := start; j <= end-1; j++ {
2726
//If current element is smaller than or equal to pivot
28-
if(arr[j] <= pivot){
27+
if arr[j] <= pivot {
2928
i++
3029
Swap(&arr[i], &arr[j])
3130
}
3231
}
3332

34-
Swap(&arr[i + 1], &arr[end])
33+
Swap(&arr[i+1], &arr[end])
3534

3635
return (i + 1)
3736
}
3837

3938
/*The main function that implements QuickSort
40-
arr[] -> Array to be sorted
41-
start -> Starting index
42-
end -> Ending index
39+
arr[] -> Array to be sorted
40+
start -> Starting index
41+
end -> Ending index
4342
*/
4443
func QuickSort(arr []int, start, end int) {
45-
if(start < end){
44+
if start < end {
4645
//pi is partitioning index, arr[p] is now at right place
4746
var pi int = Partition(arr, start, end)
4847

4948
//Separately sort elements before partition and after partition
50-
QuickSort(arr, start, pi - 1)
51-
QuickSort(arr, pi + 1, end)
49+
QuickSort(arr, start, pi-1)
50+
QuickSort(arr, pi+1, end)
5251
}
5352
}
5453

55-
func PrintArray(arr []int, size int){
56-
for i:=0; i < size; i++ {
54+
func PrintArray(arr []int, size int) {
55+
for i := 0; i < size; i++ {
5756
fmt.Printf("%d ", arr[i])
5857
}
5958
fmt.Printf("\n")
@@ -63,8 +62,8 @@ func main() {
6362
arr := []int{10, 7, 8, 9, 1, 5}
6463
var n int = len(arr)
6564

66-
QuickSort(arr, 0, n - 1)
65+
QuickSort(arr, 0, n-1)
6766

6867
fmt.Println("Sorted array is: ")
6968
PrintArray(arr, n)
70-
}
69+
}

0 commit comments

Comments
 (0)