Recursive method, help :)

hi everybody ... this is my method

public Data matchByInd1(Data data, Vector vector, int i) {

Data _data;

Data notFound = new Data("notFound");

if (i < vector.size()) {

_data = (Data) vector.elementAt(i);

if (!_data.isVisited() && matchInd1(data, _data)) {

_data.setVisited();

return _data;

}else {

i+=1;

matchByInd1(fact, kb, i);

}

}

return notFound;

}

Right, this is method is some sort of recursive member function, this is given a vector and a data, the method searches, in the vector, for such a data and if it finds it the data is returned otherwise it returns notFound.

My problem is that this method do finds any given data which is stored in the vector however such a data is not returned. The method always returns the first element stored in the vector.

How I can fix this problem? I do not want to fix it by using for() or while() :) ...

Thank you

Pepe

[1009 byte] By [pepetronsa] at [2007-9-29 16:34:35]
# 1

Good grief, don't cross-post:

http://forum.java.sun.com/thread.jsp?thread=464520&forum=31&message=2133578

http://forum.java.sun.com/thread.jsp?thread=464518&forum=426&message=2133573

http://forum.java.sun.com/thread.jsp?thread=464515&forum=4&message=2133567

http://forum.java.sun.com/thread.jsp?thread=464514&forum=4&message=2133564

http://forum.java.sun.com/thread.jsp?thread=464475&forum=426&message=2133217

You're new to the Forum, so you can claim ignorance. But if you have a question, post it to one forum. You waste people's time when you send the same question to multiple forums. No one can tell if you've gotten your answer elsewhere.

It's considered rude, and you depend on the goodwill of strangers for answers. Just one forum to a question, please. - MOD

duffymoa at 2007-7-15 14:56:55 > top of Java-index,Other Topics,Algorithms...