+ 1

Data structures insert sorted list code

Hi! I have this code in a java data structure project. This code inserts a new element with a key into a list of elements. The problem is that when we do our countings after like the 100000 element it goes through a infinite loop and we dont know what to do https://sololearn.com/compiler-playground/cNp4mwSL5u8u/?ref=app

16th Apr 2024, 1:51 PM
Elen
Elen - avatar
1 ответ
+ 3
The issue might be related to the insertion logic in your code. One potential reason for the infinite loop after a certain number of elements could be due to how new elements are being inserted and maintained in sorted order within the list. It's very important to ensure that the pointers and the ordering of elements are correctly set in each insertion scenario to prevent unexpected behavior. You have a typo in the line listElements++:, check this out.
16th Apr 2024, 3:55 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar