Code not working properly
@lakshit
What is the need of check function. Why are you not inserting element if single element already exist.Consider this testcase
1 2 3 5 5 4 1 2 3
Here there is link from 4 to 1. But your code will not insert any number after 5 since 5 occur twice.
But in the question it is given that all the integers are distinct , once any no repeats a cycle is there.
@lakshit
Ok so if element start appearing again, you are not inserting elements in your list. Great.
But there are few mistakes in your code.
- write cin>>d; at the end of while loop then you don’t need insertnode(d) in line 87.
- you don’t need line 97 to 99. What are you trying to do in these lines?
- you don’t need detectcycle function anymore.
I have modified your code. plz check here
https://ide.codingblocks.com/s/230969
I think you got 100 points for this question. Please mark this doubt as resolved.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.