https://ide.geeksforgeeks.org/VgFkyiwhqZ----what’s the error in code I have implemented your suggestion but still something is wrong, help me out
Circular linked list problem 1
the way you are creating the linked list, this list can never have a loop. see, for every new integer you read, you are creating a new node, which makes it a simple linked list not circular.
say for eg. 2 3 4 5 6 7 5 -1, here even if you read 5 two times, you are creating two different nodes for same data 5.
Hint: you can detect the loop while reading the data. the approach you followed is helpful when a pre-built linked list is given to you as input.
Thanks
then sir how to input cicular linked list what the approach should be? so that the code works?
to make a circular linked list, you need to make a hashmap. hashmap will be like
HashMap<int,Node>… key as integer and value as the Node object you created.
and then for every input, you need to search that in this hashmap, and if it exists, then you dont need to create a new node, just use the node you created earlier
But in this problem, do you really have to create a circular linked list? think about it.
thanks
sir i not able to think how to get in a circular linked list fashion please make changes in the code and point them out all i m thinking is of creating a new class for linked list but that is not the case in this question so please make changes
input**-------------
just a simple question.
can you write a program to detect first duplicate number.
eg. 1 2 3 4 5 9 8 7 15 4 3 23 9
output: first duplicate number is 4 and its position is 10.
please try to write code for this problem. then i will tell you the solution of above problem.
thanks