Advanced Array Concepts - Bubble Sort
Advanced Array Concepts - Bubble Sort
Concepts
Objective
Sort array elements using the bubble
sort algorithm
- Sorting (ascending/descending)
- Sorting array of objects
2
Sorting Array Elements Using the
Bubble Sort Algorithm
• Sorting
– The process of arranging a series of objects in
some logical order
• Ascending order
– Begin with the object that has the lowest value
• Descending order
– Begin with the object that has the largest value
3
Using the Bubble Sort Algorithm
• An algorithm is a process or set of steps that solve
a problem.
• In the ascending bubble sort algorithm, you
repeatedly compare pairs of items, swapping
them if they are out of order, and eventually
creating a sorted list.
• The bubble sort is neither the fastest nor most
efficient sorting technique, but it is one of the
simplest to comprehend and provides deeper
understanding of array element manipulation. 4
Using the Bubble Sort Algorithm
• Bubble sort
–You continue to compare pairs of
items, swapping them if they are out of
order
7
Sorting Arrays of Objects
• You can sort arrays of objects in
much the same way that you sort
arrays of primitive types
–Major difference
• Make the comparison that determines
whether to swap two array elements
• Sort based on a particular object field
8
Sorting Arrays of Objects
9
Lab. Activities
10