Question: Using Java You are going to write a program that is capable of sorting an array of random integers. There are several well known sorting

Using Java

You are going to write a program that is capable of sorting an array of random integers. There are several well known sorting algorithms ( if you don't want to come up with your own ). Shell sort, selection sort, bubble sort, merge sort, quick sort, and counting sort. You can come up with your own idea or use one of these. Here are some other details that might be of interest to you.

When the program starts, the user is asked several questions. The min random number, the max random number, and the total number of random numbers to be sorted. The user is also asked if they would like to see the sorted and unsorted lists printed. NOTE: this is to be done BEFORE you generate the random numbers and before your preform your sort. Assume that for the extra credit challenge, I will set the rang to be 1-1000, and I will ask for 1 million integers to be sorted. I will also not want to see the unsorted and sorted lists. programs that use nlogn algorithms or programs that use 2n algorithms to find the number that the user wanna find after the sorted number.

Two basic sorting algorithms

In case you have trouble coming up with your own sorting algorithm, allow me to describe two relatively simple algorithms.

The first, and worst, is called Rob Sort. Here is what you do. First, you have an array of random integers as input (lets call it a). Generate two numbers between 0 and the number a.length-1. Lets call these numbers i, and j. Then swap a[i] and a[j]. Then we check to see if the array is sorted. If it is, we are done. If not, then generate two more random numbers and so on. How do you check to see if an array is sorted? First check to see that a[0] < a[1]. Then check to see if a[1] < a[2], and so on, all the way up to a[a.length-2] and a[a.length-1].

I doubt many of you will want to do Rob Sort. So let me suggest bubble sort. Here is what you do. You make a pass through the array. For each pass you check to see if a[0] < a[1]. If not, swap a[0] and a[1]. Then check to see if a[1] < a[2], if not, then swap. Then check a[2] and a[3], and so on. Again, all that is considered one pass through the array. Then if you do a.length passes, you are assured to have a sorted array!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!