Algorithm 2

algorithm2

The bubbleSort algorithm compares two numbers in an array and swaps them if the larger number is on the left. It repeats this until it doesn’t swap at all which would indicate that the  array is sorted in least to greatest order.

The swap algorithm takes in an array of values and two integers (each indicating a different address in the array) switches the two variables values and returns the array with the two values swapped.

The bubbleSort algorithm relies on the swap function in order to do its job properly. The whole concept of bubbleSort revolves around its ability to swap to values based on certain conditions. The swap function could theoretically have a use in any function but it was specially created for this one.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s