0
Why no output?
I made one with loop: not working now with recursion : no outputđđ¶đ„ https://code.sololearn.com/cesAOsP31kz9/?ref=app https://code.sololearn.com/cu4RUDsDw927/?ref=app
7 Respostas
+ 2
It's an infinite loop because you call bst() with the same values again and again. Change mid++ in line 24 to ++mid, same with mid-- in line 26. This way mid is in/decreased before the recursive function call.
+ 1
Thanks a lot Anna. Can you look into the second one?
+ 1
I tried the second one a couple of times, all I see is "an error occurred, check your internet connection". What kind of output do you get?
The sorting algorithm in lines 35-44 with two nested loops might be wrong. With bubble sort, you only need to check if any item is bigger than the next one and swap them if necessary. You can do that in a single loop, for(i=0; i<items-1;i++) { if(item[i] > item[i+1]) swap() }. Maybe the nested loops lead to an endless loop as well because you compare every item with every other item đ€
+ 1
I was able to run the code now. Same problem as with the first one: change mid++/-- to ++/--mid in lines 79/82.
+ 1
Thanks a lot for your helpđ.
0
Where do you print the output?
0
bst causes an infinite loop (just put a cout inside of it and you'll see). Usually in a function that you want to call recursively there should be a "terminating" statement, which will return a fixed value for a particular value that will end the recursion, but bst doesn't have such thing and keeps calling itself on and on.