Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 Lab22C that will create a matrix (2-dimensional array) of random
numbers and then sort that array.
Write a void method that receives a 2-dimensional array (4 rows, 4 columns) of integers.
It should:
i. Copy all the values from the 2D array into a one-dimensional integer array that
is big enough to fit all the values.
ii. Sort the 1D 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 1-dimensional array back into the 2D array, so
that they will be sorted in the 2D array as well. (The first 4 values go in the first
row, next 4 in the second row, etc.)
In your main method:
i. Create a 2 dimensional array of integers with 4 rows and 4 columns
ii. Fill the array with random numbers between 0 and 50
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 3 variables: smallest, index & temp
set len = the array length
for loop with i starting at 0 and condition: i len-1
smallest = arr[i]
index =i
for loop with k starting at i+1 and condition: k len
if arr [k] smallest
smallest =arr[k]
index =k
end if
end for loop
swap arr[i] and arr[index] 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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions