How do I sort an array in descending order without using the sort function?
2 ビュー (過去 30 日間)
古いコメントを表示
A = [2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19]
0 件のコメント
採用された回答
Thorsten
2015 年 11 月 5 日
You can use bubble sort:
swapped = 1;
while swapped
swapped = 0;
for i=1:numel(A)-1
if A(i+1) > A(i)
temp = A(i); A(i) = A(i+1); A(i+1) = temp; swapped = 1;
end
end
end
0 件のコメント
参考
カテゴリ
Help Center および 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!