Bubble sort alternative

#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=n-1;i>0;i–)
{
for(int j=0;j<i;j++)
{
if(a[j]>a[j+1])
swap(a[j],a[j+1]);
}
}
for(int i=0;i<n;i++)
{
cout<<a[i]<<endl;
}
return 0;
}
does the above code work same as bubble sort?

Yes
There is no difference whether you start iteration from starting or end

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.