Skip to content

Examples

Stardust D.L edited this page Jan 17, 2018 · 1 revision

Examples

Quick Sort

func{
    sort=(a)=>func{
        _sort=(l,r)=>func{
            i:=l,j:=r,
            if(l<r){
                t:=a[l],
                while(i!=j){
                    while(i<j & a[j]>=t){j=j-1},
                    if(i<j){a[i]=a[j]},
                    while(i<j & a[i]<=t){i=i+1},
                    if(i<j){a[j]=a[i]}
                },
                a[i]=t,
                _sort(l,i-1),
                _sort(i+1,r)
            }
        },
	    _sort(0,len(a)-1)
    },
    a=list(select(list(range(1,20)),x=>random.next(50))),
    print(a),
    sort(a),
    print(a)
}
Clone this wiki locally