Header Ads

Learn Together, Stay Connected.

Bubble Sort- C++


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define IO ios_base::sync_with_stdio(0),cin.tie(0)

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


}



int main()
{
IO;

int arr[]={5,1,4,3,2,0};

int n=sizeof(arr)/sizeof(arr[0]);

bubble(arr,n);

for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
cout<<endl;

return 0;
}

No comments

Theme images by Dizzo. Powered by Blogger.