전체 글(164)
-
0401 연결리스트로 구현한 이진트리 Preorder Traversal (Iterative) 복습
public class BinaryTree { public BinaryTreeNode root; public BinaryTree(string data) { this.root = new BinaryTreeNode(data); } public void PrintPreorderIterative() { var stack = new Stack(); stack.Push(this.root); while (stack.Count > 0) { var node = stack.Pop(); Console.WriteLine("{0}", node.data); if (node.right != null) { stack.Push(node.right); } if (node.left != null) { stack.Push(node.left..
2021.04.01 -
0401 배열을 사용해 이진트리 구현하기 복습
public class BinaryTreeUsingArray { private string[] arr; public string Root { get { return this.arr[0]; } set { this.arr[0] = value; } } public BinaryTreeUsingArray(int capacity) { this.arr = new string[capacity]; } public void AddLeft(int parentIndex,string data) { var leftIndex = (parentIndex * 2) + 1; this.arr[leftIndex] = data; } public void AddRight(int parentIndex,string data) { var right..
2021.04.01 -
0401 연결트리로 구현한 이진트리 복습
public class BinaryTreeNode { public string data; public BinaryTreeNode left; public BinaryTreeNode right; public BinaryTreeNode(string data) { this.data = data; } } public class BinaryTree { public BinaryTreeNode root; public BinaryTree(string data) { this.root = new BinaryTreeNode(data); } public void PrintPreorderTraversal() { this.PreorderTraversalImple(this.root); } private void PreorderTra..
2021.04.01 -
0331 이진트리
Binary Tree preorder 부모노드를 먼저 순회하고, 다음 왼쪽 서브 트리를, 마지막으로 오른쪽 서브트리를 순회 배열에 이진 트리를 저장하는 방식은 기본적으로 트리 레벨 순으로 왼쪽>오른쪽으로 저장 A[0] = 루트, A[1] = A의 왼쪽 자식, A[2] = A 자식의 오른쪽 형제 public class BinaryTreeArray { private string[] arr; public string Root { get { return this.arr[0]; } set { this.arr[0] = value; } } public BinaryTreeArray(int capacity) { this.arr = new string[capacity]; } public void SetLeft(int pa..
2021.03.31 -
0330 Tree 트리
여러 노드들이 가지처럼 연결되어 있는 비선형적 자료구조(Non-linear Data Structure) 트리는 계층적 구조를 가지는 사이클이 없는 그래드(Acrylic graph)의 일종이다. 가장 위에 루트로부터 출발하며, 그 밑에 여러 자식 노드들을 가지는 구조 (순회 x) 그 밑에 0개 이상의 자식 노드를 가질 수 있고, 그 자식 노드 각각은 다시 자기 자신의 자식 노드를 가질 수 있다. 루트 간선 edge 두 모드를 잇는 링크 자식 child 부모 parent 형제 sibling 부모가 같은 노드들 단말 leaf 자식을 갖지 않는 하단의 노드 높이 height 특정 노드에서 루트 사이의 길이 (윗쪽 방향으로 계산, 간선으로 측정) 깊이 depth 루트에서 노드까지 길이 (아랫쪽 방향) 트리 높이 ..
2021.03.30 -
0330 Stack
스택은 가장 최근에 넣은 데이터를 먼저 꺼내서 사용하는 선형적인 자료구조(linear data structure) top에 데이터를 추가(push), 데이터를 꺼낼 때 (pop)도 탑에서 배열/연결 리스트로 구현 ●Array Stack (고정 배열) push 메서드에서는 탑 인덱스를 하나 증가시킨 후에 새 요소 추가 (탑 = -1) pop 메서드에서는 탑 인덱스 요소를 가져오고 탑 인덱스 하나 감소 public class StackArray { //top private int top; //배열 생성 private string[] arr; public bool IsEmpty { get { return this.top == -1; } } public StackArray(int capacity) { this...
2021.03.30