Improving bubblesort to run faster?
이전 댓글 표시
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
2013년 2월 13일
0 개 추천
Have you tried using the sort() function?
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!