Code programming

computer science

Description

COSC 111 – Assignment 7


Bubble Sort


In this assignment you will be sorting an array of numbers using the bubble sort algorithm. You

must be able to sort both integers and doubles, and to do this you must overload a method.

Bubble sort work by repeatedly going over the array, and when 2 numbers are found to be out

of order, you swap those two numbers.

This can be done by looping until there are no more swaps being made, or using a nested for

loop, meaning the array of length n is checked n 2 times.

Sample Run #1


Please enter the # of numbers to be sorted: 4

Enter 1 for int's or 2 for doubles: 2

Enter number: 4

Enter number: 3

Enter number: 2

Enter number: 1

3.0, 4.0, 2.0, 1.0

3.0, 2.0, 4.0, 1.0

2.0, 3.0, 4.0, 1.0

2.0, 3.0, 1.0, 4.0

2.0, 1.0, 3.0, 4.0

1.0, 2.0, 3.0, 4.0


Sample run #2


Please enter the # of numbers to be sorted: 5

Enter 1 for int's or 2 for doubles: 1

Enter number: 11

Enter number: 5

Enter number: 6

Enter number: 2

Enter number: 4

5, 11, 6, 2, 4

5, 6, 11, 2, 4

5, 6, 2, 11, 4

5, 6, 2, 4, 11

5, 2, 6, 4, 11

5, 2, 4, 6, 11

2, 5, 4, 6, 11

2, 4, 5, 6, 11


Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.