diff options
Diffstat (limited to '260/DEPENDENCIES/quicksort.sci')
-rw-r--r-- | 260/DEPENDENCIES/quicksort.sci | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/260/DEPENDENCIES/quicksort.sci b/260/DEPENDENCIES/quicksort.sci new file mode 100644 index 000000000..eb3119d86 --- /dev/null +++ b/260/DEPENDENCIES/quicksort.sci @@ -0,0 +1,35 @@ +function xsort = quicksort(x)
+ n= length(x)
+ pivot = x(1)
+if n == 0 then
+ xsort = []
+elseif n == 1 then
+ xsort = x(1)
+ else
+ j = n
+ for i = 2:n
+ if pivot < x(i) then
+ for j = j:-1:i
+ if pivot > x(j) then
+ t = x(i)
+ x(i) = x(j)
+ x(j) = t
+ break
+ end
+
+ end
+
+ end
+
+ if j == i then
+ if i == n & pivot > x(i) then
+ xsort = [ quicksort( x(2:i) ) pivot]
+ else
+ xsort = [ quicksort( x(2:i-1) ) pivot quicksort( x(i:n) )]
+ break ;
+ end
+ end
+ end
+end
+
+endfunction
\ No newline at end of file |