Answered step by step
Verified Expert Solution
Link Copied!

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. i.e 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 built-in sort () function.
You can use any algorithm you know to solve this problem. Here we provide the pseudo-code of two methods: bubble sort and selection sort.
Bubble sort:
x= Input
for i=1 : length (x)
for j=1 : length (x)-i
do: swap x(j) and x(j+1) if x(j)>x(j+1)
end for
end for
return x
Selection sort:
x= Input
for i=1 : length (x)
do: initialize min_idx (index of minimum element) as i
for j=i+1 :length (x)
end for
do: swap x(i) and x(min_idx) if i not equal to min_idx
end for
return x
Function
\table[[1,function [res]= sortascending(input)],[2,]]
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions

Question

What five theories explain our need for sleep?

Answered: 1 week ago

Question

5. Prepare for the role of interviewee

Answered: 1 week ago

Question

6. Secure job interviews and manage them with confidence

Answered: 1 week ago