guys i didint understand this part for(int j=1;j<max-i;j++){ what is the point of this part (bubble sort stuff)..please tell wit | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

guys i didint understand this part for(int j=1;j<max-i;j++){ what is the point of this part (bubble sort stuff)..please tell wit

void bubble(int str[],int max ){ for(int i=0;i<max;i++){ for(int j=1;j<max-i;j++){ if(str[j-1]>str[j]){ int temp=str[j]; str[j]=str[j-1]; str[j-1]=temp; } } } }

3rd Jun 2020, 12:25 PM
Abc def
Abc def - avatar
3 Answers
+ 2
Abc def In this method you search first the bigest number and you put it in the last of the array, and whene you do that for the first time;: you didn't need to compare the last element in the array by someone cuz you know that is the bigest one:; and that why you use (j<max-i)..,,
3rd Jun 2020, 12:58 PM
Amine Laaboudi
Amine Laaboudi - avatar
0
okey i get it but why is j=1
3rd Jun 2020, 4:56 PM
Abc def
Abc def - avatar
0
Abc def j start by 1 cuz in if statment we compare with str[j-1] and str[j] :: if u want u can let j start by 0 but inside if statment u should compare between str[j] and str[j+1] :;;
3rd Jun 2020, 8:11 PM
Amine Laaboudi
Amine Laaboudi - avatar