0

pls explain to me a logic of my code

this is bubble sort pls explain to the logic of may code

20th Mar 2020, 5:24 PM
Dawin Travero
Dawin Travero - avatar
4 Antworten
20th Mar 2020, 5:38 PM
Kevin ★
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; }
20th Mar 2020, 5:35 PM
Dawin Travero
Dawin Travero - avatar
0
explain to me pls
20th Mar 2020, 5:36 PM
Dawin Travero
Dawin Travero - avatar
0
ty sir
20th Mar 2020, 5:38 PM
Dawin Travero
Dawin Travero - avatar