0
pls explain to me a logic of my code
this is bubble sort pls explain to the logic of may code
4 Antworten
0
// Bubble Sort
#include <iostream>
using namespace std;
int main()
{
int i,j,temp,pass=0;
int a[5] = {5,4,1,2,3};
cout<<"Input List \n";
for(i=0;i<5;i++){
cout<<a[i]<<endl;
}
cout<<endl;
for(i=0;i<5;i++){
for(j=i+1;j<5;j++){
if(a[j]<a[i]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}}
pass++;
}
cout<<"Sorted Element List \n"<<endl;
for(i=0;i<5;i++){
cout<<a[i]<<endl;
}
cout<<"Number of passes taken to sort the list : "<<pass<<endl;
return 0;
}
0
explain to me pls
0
ty sir