June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -0,0 +1,49 @@
# Project : Sorting algorithms/Quicksort
# Date : 2018/03/04
# Author : Gal Zsolt (~ CalmoSoft ~)
# Email : <calmosoft@gmail.com>
test = [4, 65, 2, -31, 0, 99, 2, 83, 782, 1]
see "before sort:" + nl
showarray(test)
quicksort(test, 1, 10)
see "after sort:" + nl
showarray(test)
func quicksort(a, s, n)
if n < 2
return
ok
t = s + n - 1
l = s
r = t
p = a[floor((l + r) / 2)]
while l <= r
while a[l] < p
l = l + 1
end
while a[r] > p
r = r - 1
end
if l <= r
temp = a[l]
a[l] = a[r]
a[r] = temp
l = l + 1
r = r - 1
ok
end
if s < r
quicksort(a, s, r - s + 1)
ok
if l < t
quicksort(a, l, t - l + 1 )
ok
func showarray(vect)
svect = ""
for n = 1 to len(vect)
svect = svect + vect[n] + " "
next
svect = left(svect, len(svect) - 1)
see svect + nl