feat(csharp): add csharp code for array binary tree (#632)

This commit is contained in:
hpstory
2023-07-20 18:54:40 +08:00
committed by GitHub
parent 2b7d7aa827
commit 2af77ff565
3 changed files with 184 additions and 37 deletions

View File

@ -16,12 +16,16 @@ public class Trunk {
}
};
public class PrintUtil {
public static class PrintUtil {
/* Print a list */
public static void PrintList<T>(IList<T> list) {
Console.WriteLine("[" + string.Join(", ", list) + "]");
}
public static string PrintList<T>(this IEnumerable<T?> list) {
return $"[ {string.Join(", ", list.Select(x => x?.ToString() ?? "null"))} ]";
}
/* Print a matrix (Array) */
public static void PrintMatrix<T>(T[][] matrix) {
Console.WriteLine("[");
@ -131,4 +135,4 @@ public class PrintUtil {
TreeNode tree = TreeNode.ListToTree(list.Cast<int?>().ToList());
PrintTree(tree);
}
}
}