Bubble Sort
Bubble Sort
SORT
BUBBLE
SORT Student’s name:
• Sorting algorithm
• Types of sorting algorithm
BUBBLE
SORT
SORTING
ALGORITHM
Type of sorting algorithm
• Selection sort
• Quick sort
• Merge sort
• Bubble sort
• etc
BUBBLE
SORT
BUBBLE
BUBBLE
BUBBLE
BUBBLE
SORT
SORT
Describe object
BUBBLE
SORT
THE ALGORITHM
THE ALGORITHM
“ Bubble” part of Bubble Sort
5
BUBBLE
SORT
THE ALGORITHM
“ Bubble” part of Bubble Sort
1
35
BUBBLE
SORT
COMPLEXITY
BUBBLE
SORT
THE PROCEDURE
BUBBLE
SORT
COMPARING THE VALUE
1 3 5 2
BUBBLE
SORT
COMPARING THE VALUE
1 2 5 3
BUBBLE
SORT
COMPARING THE VALUE
1 2 5 3 1 2 3 5
BUBBLE
SORT
THE SWAPPING
X Y
BUBBLE
SORT
THE SWAPPING
WTF man?
Idiots!
Gà!
Ngu!
X
Óc cko!
BUBBLE
SORT
THE SWAPPING
Temp
or Z
X Y
or whatever
you want
BUBBLE
SORT
THE SWAPPING
X Y Temp = X
BUBBLE
SORT
THE SWAPPING
X=Y Y Temp = X
BUBBLE
SORT
THE SWAPPING
BUBBLE
SORT
FLOW CHART
FLOWCHART
BUBBLE
SORT
THE CODE
for(i=1;i<=4;i++)
{
for(j=i;j<=5;j++)
if (a[i]>a[j]) //If the value at i is greater than
the value at j
{
temp=a[j]; //swaping
a[j]=a[i];
a[i]=temp;
}
}
for(i=1;i<=5;i++) //print the array on the screen
{
cout<<a[i]<<" ";
}
}
PROGRAM
PROGRAM
• Needed Functions: Swap & 2 For loops
BUBBLE
SORT
PROGRAM
User interface
BUBBLE
SORT