blob: eb3119d862989308606d2c9cfcb78e1b26be6300 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
|