Professional Documents
Culture Documents
Date:
AIM
To write a c++ program to implement bubble sort algorithm to sort the given numbers
ALGORITHM:
Step 3: Starting with the first element(index = 0), compare the current element with the
next element of the array.
Step 4: If the current element is greater than the next element of the array, swap them.
Step 5: If the current element is less than the next element, move to the next element
Step 6: Repeat step 3 to 6 for n-1 passes or until no swapping is done in a pass
PROGRAM:
#include<iostream>
int temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
swaps = 1;
if(!swaps)
break;
int main() {
int n=10;
int arr[]={23,12,56,34,89,90,5,21,77,11};
cout<<arr[0];
display(arr, n);
bubbleSort(arr, n);
display(arr, n);