Mình cảm thấy những bài như thế này rất hay.Nhưng thực chất vẫn có một số điểm mình chưa rõ lắm hy vọng có chú thích kỹ hơn.
Xây dựng cấu trúc dữ liệu của cây nhị phân tìm kiếm trong lập trình C#
Visual C# Code:
namespace BSTStructure { { public BSTree left; public BSTree right; { data = key; } public BSTree Left { { return left; } { } } public BSTree Right { { return right; } { } } { { return data; } { } } { { } { } } } { public BSTree root; { } { } { Console.Write(node.data + " "); PreorderTraverse(node.left); PreorderTraverse(node.right); } { InorderTraverse(node.left); Console.Write(node.data + " "); InorderTraverse(node.right); } { PostorderTraverse(node.left); PostorderTraverse(node.right); Console.Write(node.data + " "); } { } } }
Một ví dụ minh họa:
Visual C# Code:
{ class Program { { int key; Console.WriteLine("Cac gia tri duoc them vao cay:"); { key = random.Next(100); Console.Write(key + " "); tree.InsertNode(key); } Console.WriteLine("\n\nDuyet tien tu:"); tree.PreorderTraverse(tree.root); Console.WriteLine("\n\nDuyet trung tu:"); tree.InorderTraverse(tree.root); Console.WriteLine("\n\nDuyet hau tu:"); tree.PostorderTraverse(tree.root); Console.Write("\n\nNhap khoa can tim kiem:"); } } }
Mình cảm thấy những bài như thế này rất hay.Nhưng thực chất vẫn có một số điểm mình chưa rõ lắm hy vọng có chú thích kỹ hơn.