Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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, 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, upStep 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