Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a function sortAscending ( ) which sorts an numeric array in ascending order. This function should fulfill the following requirements The input to the
Create a function sortAscending which sorts an numeric array in ascending order. This function should fulfill the following requirements
The input to the function can be either a row vector, a column vector or a scalar of numeric data types othervise the function returns empty array
If the input is a row vector. the function returns a row vector. if the input is a column vectors. the function returns a column vector scalar input returns a scalar output.
If not empty, the output array is arranged in ascending order. ie all elements in the array are arranged in a series that begins with the least or smallest and ends with the greatest or largest.
You are NOT permitted to use the builtin sort function.
You can use any algorithm you know to solve this problem. Here we provide the pseudocode of two methods: bubble sort and selection sort.
Bubble sort:
Input
for : length
for : length
do: swap and if
end for
end for
return
Selection sort:
Input
for : length
do: initialize minidx index of minimum element as i
for :length
end for
do: swap and minidx if i not equal to minidx
end for
return
Function
tablefunction res sortascendinginput
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started