Ok, this is a Lab that I have to do tomorrow. If you could write the code real quick, I'd appreciate it! If not, I understand, lol... Thanks!
The bubble sort is the simplest kind of sort. Given an array, the bubble sort goes through the array from left to right and compares consecutive numbers. If two numbers are in the wrong order, then it will swap them. Consider the following example:
10 7 6 3 2 1
The bubble sort will first swap 10 and 7 and get the new array shown bellow.
7 10 6 3 2 1
Next, it will swap 6 and 10 and get the array.
7 6 10 3 2 1
After the first pass of the sort is complete, the array will be as follows.
7 6 3 2 1 10.
The second pass of the sort will work exactly the same way as the first pass (i.e., going from left to right swapping numbers), but it will stop one number short of the end (i.e., it doesn’t have to read the 10). If the input contains n numbers, then n passes of the array will sort it.
Write a method that sorts an array. The method can use an auxiliary method that swaps two entries in array. Test your method with different inputs. Time permitting, write a program that reads the input numbers from a file and writes the sorted number back to a file.
The bubble sort is the simplest kind of sort. Given an array, the bubble sort goes through the array from left to right and compares consecutive numbers. If two numbers are in the wrong order, then it will swap them. Consider the following example:
10 7 6 3 2 1
The bubble sort will first swap 10 and 7 and get the new array shown bellow.
7 10 6 3 2 1
Next, it will swap 6 and 10 and get the array.
7 6 10 3 2 1
After the first pass of the sort is complete, the array will be as follows.
7 6 3 2 1 10.
The second pass of the sort will work exactly the same way as the first pass (i.e., going from left to right swapping numbers), but it will stop one number short of the end (i.e., it doesn’t have to read the 10). If the input contains n numbers, then n passes of the array will sort it.
Write a method that sorts an array. The method can use an auxiliary method that swaps two entries in array. Test your method with different inputs. Time permitting, write a program that reads the input numbers from a file and writes the sorted number back to a file.