Professional Documents
Culture Documents
Bubble Sort: Presented By:-012: - Shubham Koshti 042: - Het Shah 047: - Ziyan Shaikh
Bubble Sort: Presented By:-012: - Shubham Koshti 042: - Het Shah 047: - Ziyan Shaikh
Bubble Sort: Presented By:-012: - Shubham Koshti 042: - Het Shah 047: - Ziyan Shaikh
Presented By :-
012 :- Shubham Koshti
042 :- Het Shah
047 :- Ziyan Shaikh
What is Sorting
● Bubble Sort
● Selection Sort
● Insertion Sort
● Merge Sort
● Quick Sort
● Heap Sort
Bubble Sort
Bubble_sort(A[],N)
TEMP=A[J]
A[J]=A[J+1]
A[J+1]=TEMP
END IF
END FOR
END FOR
Step 4: EXIT
Program
#include<stdio.h> for(i=0;i<n-1;i++) printf(“\n\n”);
Int main() {
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
{
{
{
Int n;
if(a[j]>a[j+1]) printf(“\n a[%d] : %d”,i,a[i]);
printf(“Enter Size of Array : ”);
{
}
scanf(“%d”,&n);
int temp;
Int a[n],i,j; }
temp=a[j];
for(i=0;i<n;i++)
a[j]=a[j+1];
{ a[j+1]=temp;
scanf(“%d”,&a[i]); }
} }
Real Life Example
● Imagine there are five cars all travelling down a straight road.
They are all being driven on cruise control, but each of the cars’
speeds have been set to slightly different values.
● When a car is travelling faster than the car in front, it will
overtake it, and occupy the slower car’s position in the traffic.
● This will keep happening, with each car switching positions with
any slower car in front of it.
● Eventually the cars will sort themselves according to their
speeds, with the fastest car being at the front of the queue of
traffic.