Possible Duplicate:
Can every recursion be converted into iteration?
Are there problems in which one must use recursion and there is no way to do it iteratively ? For instance deleting the files within a sub-folder's .
public static boolean deleteFile(String sFilePath)
{
File oFile = new File(sFilePath);
if(oFile.isDirectory())
{
File[] aFiles = oFile.listFiles();
for(File oFileCur: aFiles)
{
deleteFile(oFileCur.getAbsolutePath());
}
}
return oFile.delete();
}
I can't think of an iterative version of the above one as we must be knowing before hand how many level of folders are actually there and if we introduce a new sub folder we'll have to change the code.Is it possible to make an iterative version of the above code in such a way that future code change won't be required ?