非再帰的にこの再帰的ループを変更するには? 私はこの方法が簡単な方法だと知っていますが、私はこの解決法の非再帰的な方法に興味があります。再帰のないフォルダツリーを歩くC#
using System;
using System.IO;
namespace NonRecursion {
class NonRecursion {
static void Main() {
string createPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string getPath = createPath + @"\folder";
GetDirsPath(getPath);
Console.ReadKey();
}
static void GetDirsPath(string getPath) {
string[] dirs = Directory.GetDirectories(getPath);
for (int i = 0; i < dirs.Length; i++) {
Console.WriteLine(dirs[i]);
GetDirsPath(dirs[i]);
}
}
}
}
この機能のみを変更できますか?
static void GetDirsPath(string getPath) {
string[] dirs = Directory.GetDirectories(getPath);
for (int i = 0; i < dirs.Length; i++) {
Console.WriteLine(dirs[i]);
GetDirsPath(dirs[i]);
}
}
ヒント: 'GetDirsPath'のキュー<>またはスタック<>を使いたい – Sean
これはエクササイズですか?これがエクササイズでない場合、あなたのために歩く[GetDirectories](https://msdn.microsoft.com/en-us/library/ms143314(v = vs.110).aspx)のバージョンを見てください。サブフォルダツリーを作成し、すべてを単一の呼び出しで返します – Steve
そして、幅優先でも深み優先でも、必要なトラバーサルの種類によってキューとスタックを選択する必要があります。 –