Write a function custom sort(v) that takes as input a vector v and as output returns the vector w sorted into increasing order. For example, if the input is [−2 1 3 1 5], the output should be [−2 1 1 3 5]. Don’t use the built-in ”sort” function or anything similar. matlab question
function result = sort_ascending(array) i = 1; while(i <= length(array)) j = length(array); while(j > i) if (array(j) < (array(j - 1))) temp = array(j-1); array(j-1) = array(j); array(j) = temp; end j = j - 1; end i = i + 1; end result=array; end
Get Answers For Free
Most questions answered within 1 hours.