-
04/01 연결리스트로 구현한 BinaryTree & Preorder Traversal 복습자료구조/수업내용 2021. 4. 1. 10:21
Program.cs
using System; namespace Study09 { class Program { static void Main(string[] args) { Console.WriteLine("Main"); new App(); } } }
App.cs
using System; namespace Study09 { public class App { //생성자 public App() { Console.WriteLine("App"); BinaryTree tree = new BinaryTree("A"); tree.root.left = new BinaryTreeNode("B"); tree.root.right = new BinaryTreeNode("C"); tree.root.left.left = new BinaryTreeNode("D"); tree.Print(); } } }
BinaryTreeNode.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study09 { public class BinaryTreeNode { public string data; public BinaryTreeNode left; public BinaryTreeNode right; public BinaryTreeNode(string data) { this.data = data; } } }
BinaryTree.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study09 { public class BinaryTree { public BinaryTreeNode root; public BinaryTree(string data) { this.root = new BinaryTreeNode(data); } public void Print() { PrintPreorderTraversal(this.root); } public void PrintPreorderTraversal(BinaryTreeNode node) { if (node == null) return; Console.Write("{0} ", node.data); this.PrintPreorderTraversal(node.left); this.PrintPreorderTraversal(node.right); } } }
'자료구조 > 수업내용' 카테고리의 다른 글
04/02 그래프 연습 (0) 2021.04.02 04/01 수업내용 메모 (0) 2021.04.01 04/01 BinaryTree Preorder 순회 (Iterative) 복습 (0) 2021.04.01 03/31 수업내용 메모 (0) 2021.03.31 03/31 BinaryTree 전위, 중위, 후위 순회 출력 (0) 2021.03.31