Bubble
Sort Source Code
(Up to Resources
: Source Code Repository : Sorts)
This source file is an implementation of the simple Bubble Sort
algorithm. The only optimizations made are that the sort is
implemented with templates and the sort has an early exit
flag, which tells the sorting loop to exit early if no operations
occured (that is, the list is sorted).
For the templated class, the elements must have the operators >,
=, and < defined.
The sort itself is implemented as a class constructor. Basically,
the function call is in the following format:
BubbleSort<TYPE>(Array, Num);
TYPE is the data type of the elements, Array is the actual array to be sorted,
and Num is the number of elements that
are to be sorted. The array is sorted in place, so there
is no actual return value for the function.
Download
the
Source:
bubble.h