Improving bubblesort to run faster?

1 view (last 30 days)
3nore
3nore on 13 Feb 2013
Does anyone know how to make this run faster?
tic
a = [8783216623,1376710497,9690826665,1570640605,7500570041,2833455215,5428161051,9156540724,520448916,5918542685,9323641738,3120571877,1466686979,372712728,10508227,614468445,8934640773,784334388,213084816631,62069482,6699641272,1309686517,6512222692,1877042633]
b = length(a);
count_s = 0;
count_o = 0;
for i = 1:b
for n = 1:b-1
count_o = count_o +1;
if a(n) >= a(n+1)
temp = a(n);
a(n) = a(n+1);
a(n+1) = temp;
count_s = count_s + 1;
end
if count_s == 0;
display('fully sorted')
end
end
end
toc

Answers (1)

Jason Ross
Jason Ross on 13 Feb 2013
Have you tried using the sort() function?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!