데이터구조 : tree구조
출처 : https://ko.wikipedia.org/wiki/%ED%8A%B8%EB%A6%AC_%EC%88%9C%ED%9A%8C
트리 순회 - 위키백과, 우리 모두의 백과사전
위키백과, 우리 모두의 백과사전. 전산학에서 트리 순회(Tree traversal)는 트리 구조에서 각각의 노드를 정확히 한 번만, 체계적인 방법으로 방문하는 과정을 말한다. 이는 노드를 방문하는 순서에
ko.wikipedia.org
sample 데이터 :
let rootTest = {
name: 'root',
children: [
{
name: 'root-1', children: [
{
name: 'root-1-1', children: []
},
{
name: 'root-1-2', children: []
}
]
},
{
name: 'root-2', children: [
{
name: 'root-2-1', children: [
{
name: 'root-2-1-1', children: []
},
{
name: 'root-2-1-2', children: []
},
]
},
{
name: 'root-2-2', children: []
},
],
},
],
};
const renderElement = (root) => {
root.children.forEach(renderElement);
console.log(root.name, "postorder traversal")
}
renderElement(rootTest);
결과 :
기대했던대로 branch -> root 순서로 출력되는 것을 알수있다.
참고자료 :
https://www.youtube.com/watch?v=IpyCqRmaKW4&t=361s
'Javascript' 카테고리의 다른 글
자바스크립트 AES암호화 및 복호화, 파이썬에서 복호화 (0) | 2024.08.22 |
---|---|
타입스크립트 오류) error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'. (0) | 2022.10.24 |
함수 내보내기, 가져오기 관련 (0) | 2022.10.19 |
closure 클로저 (0) | 2022.10.18 |
this, (0) | 2022.10.18 |