50 likes | 75 Views
Engineering 1020. Introduction to Programming Peter King peter.king@mun.ca www.engr.mun.ca/~peter Winter 2010. ENGI 1020: Sorting. One of the most common things programs do to data is sort them
E N D
Engineering 1020 Introduction to Programming Peter King peter.king@mun.ca www.engr.mun.ca/~peter Winter 2010
ENGI 1020: Sorting One of the most common things programs do to data is sort them Sorting algorithms vary from very simple 'brute-force' methods to more complex schemes that maximize efficiency There is generally a trade-off between complexity and efficiency
ENGI 1020: Sorting We will investigate one method for sorting arrays The Bubble Sort This method is simple to describe and program This method is not the most efficient • but should be fine for smaller data sets
ENGI 1020: Sorting Bubble Sort - Starting at the bottom of the array we simple compare each element to the one above it - If the above element is less, we swap - We repeat this until we reach the top of the array - We then return to the bottom and repeat the entire process - We continue this process until no swapping is required
ENGI 1020: Sorting http://en.wikipedia.org/wiki/Bubble_sort