Question: Write a function vector_sort that takes an arbitrary-length vector as input, sorts the elements in ascending or descending order, depending on the second input (which

Write a function vector_sort that takes an arbitrary-length vector as input, sortsWrite a function vector_sort that takes an arbitrary-length vector as input, sorts the elements in ascending or descending order, depending on the second input (which should be a string) , and returns the sorted vector. If the second input is anything other than 'ascending' or 'descending' the function should print a warning and return the input vector unchanged.

Problem 2 (45 points) Write a function vector sort that takes an arbitrary-length vector as input, sorts the elements in ascending or descending order, depending on the second input (which should be a string) ,and returns the sorted vector. If the second input is anything other than ascending' or descending the function should print a warning and return the input vector unchanged. Use nested conditional structures and loops as necessary. (Do NOT use the built-in MATLAB function sort.) FOLLOW THE PROGRAM DESIGN STEPS DISCUSSED IN THE LECTURE. (Steps 2.-4. must be submitted with your solution; they can be done on paper or in a text editor) STEP 2. Describe your sorting algorithm in detail. Use a variant of"Bubble Sort" Chttps://en wikipedia wiki/Bubble sort), "Selection Sort" (https://en wikipedia.orgwiki/Selection sort), or "Insertion Sort s://en.wikipedia.org/wiki/Insertion sort STEP 3. Specify input/output arguments and program scope. STEP 4. Write a detailed structure plan implementing your algorithm that satisfies the program. scope you specified. STEP 5. Write the function vector sort based on YOUR structure plan. STEP 6. Verify /validate your program. Use your function to sort the following vectors and return/output the sorted vector: a R 7 -4 9 10 j, ascending' AND 'descending b 0 -1 3 4 5 'ascending' AND 'descending -1 6 2 7 'ascending AND descending d 4.5 16.12 10.1 10 -16.11 14 -3 21, ascending AND 'descending a 7 4 -4 9 10 1, up

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!