Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to break a recursive funktion?

807600Sep 11 2007 — edited Sep 11 2007
Hello, everybody,

I have some trivial question. I'm writing a search function to search through LinkedList. this function works recursively.
As a parameter I give the search pattern. then the function goes thought the elements of the LinkedList and checks if the search pattern is == Knot name. If search pattern is == Knot name the function should return the Knot found. if the element of the linkedList is a directory the function calls itself on current element.

my Problem is that the search function finds the search pattern but it goes further and return the wrong Knot.

Could somebody help me please????
public Knot getElement(String name){
		Knot tmpknot = null;
		for (int i = 0; i < katalogContent.size(); i++) {
			tmpknot = (Knot)katalogContent.get(i);
			
			if(name.equals(tmpknot.getName())){
				return tmpknot;    /////// I'd like to break it here
			}
			else if(tmpknot instanceof Katalog){
				((Katalog)tmpknot).getElement(name);
				break;
			}
		}
		return tmpknot;
	}
Message was edited by:
ar43r11
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 9 2007
Added on Sep 11 2007
4 comments
246 views