#include<iostream>usingnamespacestd;intmain(){intn,a[50],i,j,temp;cout<<"———————————————————————————————————————————";cout<<"\nImplementation of a Bubble Sort\n";cout<<"———————————————————————————————————————————";cout<<"\nEnter the number of elements ";cin>>n;for(i=0;i<n;i++){cin>>a[i];}for(i=0;i<(n-1);i++){for(j=0;j<n-i-1;j++){if(a[j]>a[j+1]){temp=a[j];a[j]=a[j+1];a[j+1]=temp;}}}cout<<"\nSorted elements ";for(i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n———————————————————————————————————————————\n";return0;}
Output
kodingwindow@kw:~$ g++ kw.cpp kodingwindow@kw:~$ ./a.out
———————————————————————————————————————————
Implementation of a Bubble Sort
———————————————————————————————————————————
Enter the number of elements 6
12
23
-104
-1
0
90
Sorted elements -104 -1 0 12 23 90
———————————————————————————————————————————
kodingwindow@kw:~$
Dear User, Thank you for visitng KodingWindow. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.