all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
function sorted = beadsort(a)
|
||||
sorted = a;
|
||||
m = max(a);
|
||||
if ( any(a < 0) )
|
||||
error("can't sort");
|
||||
endif
|
||||
t = zeros(m, m);
|
||||
for i = 1:numel(a)
|
||||
t(i, 1:a(i)) = 1;
|
||||
endfor
|
||||
for i = 1:m
|
||||
s = sum(t(:, i));
|
||||
t(:, i) = 0;
|
||||
t(1:s, i) = 1;
|
||||
endfor
|
||||
for i = 1:numel(a)
|
||||
sorted(i) = sum(t(i, :));
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
beadsort([5, 7, 1, 3, 1, 1, 20])
|
||||
Loading…
Add table
Add a link
Reference in a new issue