일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- bootstrap
- nav-tab
- 13237
- Algorythm
- 2909
- 트리
- 백준
- 라즈베리파이3b+
- Crawling
- 라즈비안
- 알고리즘
- ubuntu
- node.js
- 크롤링
- 2579
- 라즈베리파이3
- NAV
- raspberrypi
- Python
- 라즈베리파이
- baekjun
- algotythm
- HTML
- springboot3.x
- CSS
- 파이썬
- MongoDB
- dynaminprogramming
- dp
- 16.04
Archives
- Today
- Total
노트
[백준] 1991번 트리 순회 python 본문
n = int(input())
tree = {}
for _ in range(n):
root, left, right = input().split()
tree[root] = [left,right]
def preorder(a):
if a is not '.':
print(a,end='')
preorder(tree[a][0])
preorder(tree[a][1])
def inorder(a):
if a is not '.':
inorder(tree[a][0])
print(a,end='')
inorder(tree[a][1])
def postorder(a):
if a is not '.':
postorder(tree[a][0])
postorder(tree[a][1])
print(a,end='')
preorder('A')
print()
inorder('A')
print()
postorder('A')
'알고리즘' 카테고리의 다른 글
[백준] 14493번 과일노리 python (1) | 2023.10.01 |
---|---|
[백준] 2579번 계단 오르기 python (0) | 2023.09.22 |
[백준] 15903번 카드 합체 놀이 python (0) | 2023.09.03 |
[백준] 1197번 최소 스패닝 트리 python (0) | 2023.08.20 |
[백준] 2775번 부녀회장이 될테야 python (0) | 2023.08.13 |