summary refs log tree commit diff stats
path: root/lib/core
diff options
context:
space:
mode:
Diffstat (limited to 'lib/core')
0 files changed, 0 insertions, 0 deletions
4 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
span> ^

a690e7b26 ^
e012eb100 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23










                                          

                              
                      
 



                             

                                                                   
 
                         
proc QuickSort(list: seq[int]): seq[int] =
    if len(list) == 0:
        return @[]
    var pivot = list[0]
    var left: seq[int] = @[]
    var right: seq[int] = @[]
    for i in low(list)..high(list):
        if list[i] < pivot:
            left.add(list[i])
        elif list[i] > pivot:
            right.add(list[i])
    result = QuickSort(left) &
      pivot &
      QuickSort(right)

proc echoSeq(a: seq[int]) =
    for i in low(a)..high(a):
        echo(a[i])

let list = QuickSort(@[89,23,15,23,56,123,356,12,7,1,6,2,9,4,3])
let expected = @[1, 2, 3, 4, 6, 7, 9, 12, 15, 23, 56, 89, 123, 356]

doAssert list == expected