Question: Write a program named Lab 2 2 C that will create a matrix ( 2 - dimensional array ) of random numbers and then sort
Write a program named LabC that will create a matrix dimensional array of random
numbers and then sort that array.
Write a void method that receives a dimensional array rows, columns of integers.
It should:
i Copy all the values from the array into a onedimensional integer array that
is big enough to fit all the values.
ii Sort the array using the selection sort algorithm given below. Do not use an
automated function; write the sort routine yourself.
iii. Now copy the values from your dimensional array back into the D array, so
that they will be sorted in the array as well. The first values go in the first
row, next in the second row, etc.
In your main method:
i Create a dimensional array of integers with rows and columns
ii Fill the array with random numbers between and
iii. Print the array as a matrix with one row per line
iv Call your method, sending the array as a parameter
v Print a blank line and then print the array again.
vi Analyze your sort routine and print a statement saying what its order of
complexity is and why.
Pseudocode for sortArray:
declare variables: smallest, index & temp
set len the array length
for loop with i starting at and condition: len
smallest arri
index
for loop with starting at and condition: len
if arr smallest
smallest arr
index
end if
end for loop
swap arri and arrindex values using temp as temporary holder
end for loop
NOTE watch where the for loops end and make sure you don't put the swap statements inside the
inner for loop.
please if possible add the output, thanks
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
