From 69f256b9000c65f3fe06447e4ba62528340c04bb Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 3 Mar 2020 14:41:05 +0100 Subject: [PATCH] use LF line endings in examples/quick_sort.v --- examples/quick_sort.v | 100 +++++++++++++++++++------------------- vlib/builtin/js/hashmap.v | 26 +++++----- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/examples/quick_sort.v b/examples/quick_sort.v index a9dfdbaead..e4979343a5 100644 --- a/examples/quick_sort.v +++ b/examples/quick_sort.v @@ -1,50 +1,50 @@ -import time -import rand - -const ( - LEN = 1000 // how many random numbers to generate - MAX = 10000 // max of the generated numbers -) - -fn main() { - rand.seed(time.now().unix) - rand.next(MAX) // skip the first - mut arr := []int - for _ in 0..LEN { - arr << rand.next(MAX) - } - println('length of random array is $arr.len') - println('before quick sort whether array is sorted: ${is_sorted(arr)}') - quick_sort(mut arr, 0, arr.len-1) - println('after quick sort whether array is sorted: ${is_sorted(arr)}') -} - -fn quick_sort(arr mut []int, l int, r int) { - if l>=r { return } - mut sep := l // what is sep: [...all_value=arr[sep]...] - for i in l+1..r+1 { - if arr[i] < arr[l] { - sep++ - swap(mut arr, i, sep) - } - } - swap(mut arr, l, sep) - quick_sort(mut arr, l, sep-1) - quick_sort(mut arr, sep+1, r) -} - -[inline] -fn swap(arr mut []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] { - return false - } - } - return true -} +import time +import rand + +const ( + LEN = 1000 // how many random numbers to generate + MAX = 10000 // max of the generated numbers +) + +fn main() { + rand.seed(time.now().unix) + rand.next(MAX) // skip the first + mut arr := []int + for _ in 0..LEN { + arr << rand.next(MAX) + } + println('length of random array is $arr.len') + println('before quick sort whether array is sorted: ${is_sorted(arr)}') + quick_sort(mut arr, 0, arr.len-1) + println('after quick sort whether array is sorted: ${is_sorted(arr)}') +} + +fn quick_sort(arr mut []int, l int, r int) { + if l>=r { return } + mut sep := l // what is sep: [...all_value=arr[sep]...] + for i in l+1..r+1 { + if arr[i] < arr[l] { + sep++ + swap(mut arr, i, sep) + } + } + swap(mut arr, l, sep) + quick_sort(mut arr, l, sep-1) + quick_sort(mut arr, sep+1, r) +} + +[inline] +fn swap(arr mut []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] { + return false + } + } + return true +} diff --git a/vlib/builtin/js/hashmap.v b/vlib/builtin/js/hashmap.v index a38226a602..a9e31a4939 100644 --- a/vlib/builtin/js/hashmap.v +++ b/vlib/builtin/js/hashmap.v @@ -1,13 +1,13 @@ -// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. - -module builtin - -/* -TODO: Implement hashmap for js when hashmap for V is done. -*/ - -fn foo() { - -} +// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. +// Use of this source code is governed by an MIT license +// that can be found in the LICENSE file. + +module builtin + +/* +TODO: Implement hashmap for js when hashmap for V is done. +*/ + +fn foo() { + +}