Bubble Sort in array by using C++ in DSA

  Bubble Sort in array by using C++ in DSA

#include <iostream>
using namespace std;

void bubble_sort(int arr[], int n){
int count=1;
while(count<n){
for(int i=0; i<n-count; i++){
if(arr[i]>arr[i+1]){
int temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
count++;
}
}

void display(int arr[], int n){
for(int i=0; i<n; i++){
cout<<arr[i]<<" ";
}
}
int main() {
int arr[]={29,72,3,6,9,1};
int n=sizeof(arr)/sizeof(arr[0]);
bubble_sort(arr, n);
display(arr, n);
return 0;
}

Post a Comment

0 Comments