Improving bubblesort to run faster?

2 ビュー (過去 30 日間)
3nore
3nore 2013 年 2 月 13 日
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

回答 (1 件)

Jason Ross
Jason Ross 2013 年 2 月 13 日
Have you tried using the sort() function?

カテゴリ

Help Center および File ExchangePulsed Waveforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by