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