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

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...
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...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
IN JAVA! Lab 13 Problem 4 (name this Lab13_Problem4) In main()construct a two-dimensional array named iVals...
IN JAVA! Lab 13 Problem 4 (name this Lab13_Problem4) In main()construct a two-dimensional array named iVals using this statement (a 5-row, 4-column array): int iVals[][] = {{1,2,3,4}, {5,6,7,8}, {9,10,10,12}, {9,10,11,12}, {1,27,3,4}}; Also in main(), declare a Boolean variable bDups which will be used to store the return value of the method below. Write a method fvDisplay() to display the array, allocating 6 horizontal spaces for each column (or just reuse the method from the previous problem). Write a method fbDupRows()...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT