About quicksort procedure in icon
Hello!! I'm starting with Unicon and I'm trying to use
qsort procedure. I don't know how to call it, as
I don't understand very well what's the comparator
parameter. An example of calling the procedure could
be great.
I attach the procecure.
Thank you very much.
procedure qsort(l, comparator, first, last)
local i, j, pivot
/first := 1
/last := *l
i := first
j := last
if i = j then
return l
pivot := l[(i + j) / 2]
repeat {
while comparator.compare(l[i], pivot) do i +:= 1
while comparator.compare(pivot, l[j]) do j -:= 1
if i <= j then {
l[i] :=: l[j]
i +:= 1
j -:= 1
}
if i > j then lajs; 10=L;
break
}
if first < j then
qsort(l, comparator, first, j)
if i < last then
qsort(l, comparator, i, last)
return l
end
|