how to search in double linked list in java ?

Recommended Answers

All 8 Replies

Same as searching any other list. Start with the first entry, use a loop to check each entry to see if it's the one you want.

I have no idea what that last post means. I know it's not easy writing in a foreign language, but please try to explain completely.

Same as searching any other list. Start with the first element, use a loop to check each element to see if it's the one you want.

No. This is not a "we do your homework" site. I will help you to learn how to do it.
Let's suppose your list has a variable for the first element, and each element has a variable for the next element. Then the logic looks like this in pseudo-code:

Element current = list.firstElement
while (current != null)
   test if current is the element you are searching for
      if found, break out of loop
   current = current.next  // go on to next element
end loop

might even extend that by starting in the middle and determining what direction to go in, of course only if the list is sorted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.