+ 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; } } } }
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)..,,
0
okey i get it but why is j=1
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] :;;