Question: Programming Activity 8-2 Guidance ================================= This assignment gives you practice with searching and sorting a single dimensional array of int values. The name of the

Programming Activity 8-2 Guidance ================================= This assignment gives you practice with searching and sorting a single dimensional array of int values. The name of the array you will be using is arr. Here is the framework statement that defines arr: private static int [] arr; Here is the framework statement that creates arr: arr = new int[SIZE]; Note that arr is an array of int items. Part 1 ------ The framework comments say that the array you are to search has random values. You CANNOT assume that this array is in sorted order. You must look at each value in the array and compare it to the value of the input parameter named "key". If you find it, immediately return the array index where you found it. Since you will return from inside the loop if you get a hit, the code following the loop is only executed if you did not find it. At this point, your code should simply return -1. Part 2 ------ This week's outline contains the following bubble sort pseudocode: for (i = 0; i <= array.length - 2; i++) { for (j = 0; j <= array.length - 2 - i; j++) { if (array[j] > array[j + 1]) // Two consecutive elements are in the wrong order { swap them } } } To swap 2 items, you must use of a temporary variable. Assign the first item to the temporary variable. Assign the second item to the first item. Finally, assign the temporary variable to the second item. Here is a swapping example from this week's outline: Example (swapping elements 7 and 8: int temp = array[7]; array[7] = array[8]; array[8] = temp;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Lets break down this programming activity into two main parts Part 1 Searching an Array You are required to search for a specific key an integer in an ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!