我有recrusive功能工作正常。问题是当行数很大时它给出了stackoverflow错误。我想把它放在迭代中,可能使用for循环。在做这件事时需要一些帮助。该方法的更改递归方法迭代
private TreeSet validate(int curLine, TreeSet errorSet) {
int increment = 0;
int nextLine = 0;
if (curLine == lines.length || errorSet.size() != 0) {
return errorSet;
} else {
String line = lines[curLine];
//validation starts. After validation, line is incremented as per the requirements
increment = 1 //As per requirement. Depends on validation results of the line
if (increment > 0) {
try{
Thread.currentThread().sleep(100);
}catch(Exception ex){
System.out.println(ex);
}
nextLine = (curLine + increment);
validate(nextLine, errorSet);
}
}
return errorSet;
}
海报的描述:
的方法确实验证文本行,这些行有多少行已被跳过,如果该行是有效的指令。所以,如果该行是有效的,许多行将被跳过使用增量。如果行是无效的增量将是0
您正在调用'validate(nextLine,errorSet)'而不保存其返回值。这是故意的吗?另外,由于前面的行,'if(increment> 0)'总是成立的:'increment = 1'。解释该方法应该做什么可能是一个好主意。 – 2012-07-30 16:12:40
它工作正常,所以我没有保存它。 – FirmView 2012-07-30 16:17:17
增量不会总是> 0.如果行中有错误,则增量为0. – FirmView 2012-07-30 16:19:15