Bubble Sort in DSA C++
by DataFlair Team
Program 1
// Implementation of Bubble Sort
#include<iostream>
using namespace std;
int main()
{
system("cls");
int ar[500],n,i,j,temp;
cout<<"Enter the limit: ";
cin>>n;
cout<<"\n Enter the elements: ";
for(i=0;i<n;i++)
cin>>ar[i];
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(ar[j]>ar[j+1])
{
temp=ar[j];
ar[j]=ar[j+1];
ar[j+1]=temp;
}
}
}
cout<<"\n Sorted elements :";
for(i=0;i<n;i++)
cout<<ar[i]<<"\n";
return 0;
}
Tags: Bubble Sortbubble sort in c++bubble sort in dsa c++dsa c++dsa c++ bubble sortdsa c++ practicaldsa c++ programdsa c++ program on bubble sort
DataFlair Team
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.