Bubble Sort

This is a bubble sort (very slow sorting algorithm. Has an average run time of O(n^2) [for those of you that know what that means])

Here it is!

(Note: This is taken from my class that contained a large variety of sorting algorithms. The swap function is a useful snippet for many of these comparison sorts, so I split it into a separate function. You don’t have to leave it that way if you don’t want to.)

Just for fun, How does this algorithm work? I would prefer you not cheat and look it up, but I can’t stop you now, can I?

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s


%d bloggers like this: