Question

In: Computer Science

In Java please Your program will sort a two dimensional array (5 * 4) based on...

In Java please

Your program will sort a two dimensional array (5 * 4) based on the following:

  1. The entire array should be sorted using bubble sort based on the 1st column in ascending order and display the entire array.
  2. Reset the array to its original contents. The entire array should again be sorted using selection sort based on the 2nd column in descending order and display the entire array.
  3. Reset the array to its original contents. The entire array should again be sorted using shell sort based on the 3rd   column in ascending order and display the entire array
  4. Reset the array to its original contents. The entire array should again be sorted using insertion sort based on the 5th   row in ascending order and display the entire array

Ask the user for a number, search for that number in the 5th row of the array that was sorted via insertion sort, using binary search. Display the entire column.

Your array could be declared as a global variable since it is being used everywhere.

For example, given the following array:

5

3

2

16

9

8

10

17

4

7

11

18

2

5

9

12

7

9

4

10

5

3

2

16

9

8

10

17

4

7

11

18

2

5

9

12

5th row

Insertion

Ascending

7

9

4

10

1st column

Bubble

Ascending

2nd column

Selection

Descending

3rd column

Shell

Ascending

After bubble sort

2

5

9

12

4

7

11

18

5

3

2

16

7

9

4

10

9

8

10

17

After selection sort (Descending order)

7

9

4

10

9

8

10

17

4

7

11

18

2

5

9

12

5

3

2

16

Do the same kind of thing for shell sort (Ascending order based on the 3rd column)

After Insertion sort

2

5

3

16

10

9

8

17

11

4

7

18

9

2

5

12

4

7

9

10

What number are you searching for in the 5th row?   9

3

8

7

5

9

Make sure to modularize your program. Each of the sorts and searches must happen in their own functions. Reset the array to its original contents after each sort.

Solutions

Expert Solution

int[][] mat=new int[5][4];

for(int i=0;i<5;i++)

{

for(int j=0;j<4;j++){

mat[i][j]=sc.nextInt();

}

}

a)BUBBLE SORT

for (int i = 0; i < 5-1; i++)

            for (int j = 0; j < 5-i-1; j++)

                if (mat[j][0] > mat[j+1][0])

                {

swap(mat[j][0],mat[j+1][0]);

   swap(mat[j][1],mat[j+1][1]);

swap(mat[j][2],mat[j+1][2]);

   swap(mat[j][3],mat[j+1][3]);

                }

b)SELECTION SORT

for (int i = 0; i < 5-1; i++)

        {

            // Find the minimum element in unsorted array

            int min_idx = i;

            for (int j = i+1; j < 5; j++)

                if (mat[j][]<mat[min_idx][])

                    min_idx = j;

swap(mat[min_idx][0],mat[i][0]);

   swap(mat[min_idx][1],mat[i][1]);

swap(mat[min_idx][2],mat[i][2]);

   swap(mat[min_idx][3],mat[i][3]);

          

          

        

    }

Please please give me thumbs uo please


Related Solutions

JAVA LANGUAGE Write a program that declares a 2-Dimensional Array with 4 rows and 4 columns...
JAVA LANGUAGE Write a program that declares a 2-Dimensional Array with 4 rows and 4 columns to store integer values, and then: fill elements with values as the sum of its column index and row index, e.g., the element at row index 0 and column index 0 is (0+0=0), the element at row index 0 and column index 1 is (0+1=1). compute the sum of elements at the second row. compute the sum of elements at the third column. compute...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4...
Using Java language (in program NetBeans). 1) Using a 2 dimensional array Your company has 4 grocery stores. Each store has 3 departments where product presentation affects sales (produce, meat, frozen). Every so often a department in a store gets a bonus for doing a really good job. You need to create a program that keeps a table of bonuses in the system for departments. Create a program that has a two dimensional array for these bonuses. The stores can...
Write a program in Java to sort the given array using merge sort, quick sort, insertion...
Write a program in Java to sort the given array using merge sort, quick sort, insertion sort, selection sort and bubble sort based on the input from the user which sorting technique they wanted to use. Get the array size, array elements from the user, and also display the sorted array along with the name of the sorting technique used.
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array and remove the duplicates in-place such that each element appears only once in the input array and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Find the time complexity of your removeDuplicates() method in Big-O notation and write that in a comment line on the top...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT