Hello! I am trying to create a script in which I sort an array in descending order without using any sort function. So far, I came up with this:
A = [2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19];n = 1; while n <= length(A) if A(n) < A(n+1) tmp = A(n); A(n) = A(n+1); A(n+1) = tmp; end n = n +1; end
I thought it would be this simple, but it apparently isn't. One of the things I do not know how to do is place a value of one array into a new array, which I feel is vital in a script like this, but I did not know how to do it, so I did not implement it. Any help will be appreciated. Thank you in advance!
Best Answer