From aa270263c934f79052773da2f087ea0e2bfdad71 Mon Sep 17 00:00:00 2001 From: Ruofan XU <47302112+SleepyRoy@users.noreply.github.com> Date: Thu, 2 Jul 2020 19:32:02 +0800 Subject: [PATCH] =?UTF-8?q?example=D1=8B:=20clean=20up=20quick=5Fsort=20(#?= =?UTF-8?q?5620)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/quick_sort.v | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/examples/quick_sort.v b/examples/quick_sort.v index 45ff0eb08d..fd37a2ce20 100644 --- a/examples/quick_sort.v +++ b/examples/quick_sort.v @@ -1,4 +1,3 @@ -import time import rand const ( @@ -7,7 +6,6 @@ const ( ) fn main() { - rand.intn(gen_max) // skip the first mut arr := []int{} for _ in 0..gen_len { arr << rand.intn(gen_max) @@ -24,21 +22,14 @@ fn quick_sort(mut arr []int, l int, r int) { for i in l+1..r+1 { if arr[i] < arr[l] { sep++ - swap(mut arr, i, sep) + arr[i], arr[sep] = arr[sep], arr[i] } } - swap(mut arr, l, sep) + arr[l], arr[sep] = arr[sep], arr[l] quick_sort(mut arr, l, sep-1) quick_sort(mut arr, sep+1, r) } -[inline] -fn swap(mut arr []int, i int, j int) { - temp := arr[i] - arr[i] = arr[j] - arr[j] = temp -} - fn is_sorted(arr []int) bool { for i in 0..arr.len-1 { if arr[i] > arr[i+1] {