인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

kangjaegoo167512's profile image
kangjaegoo167512

asked

[MMORPG Game Development with C++ and Unreal Engine Series] Part 3: Data Structures and Algorithms

Tree Basics

GetHeight 부분... 이렇게 작성하면 망한건가요

Written on

·

248

0

int height = 0;
int maxHeight = 0;
int GetHeight(NodeRef root) {
	
	height++;

	if (root->children.empty()) {
		return height;
	}
	
	for (NodeRef child : root->children) {
		GetHeight(child);
		if (maxHeight <= height) {
			maxHeight = height;
		}
		height--;
	}

	return maxHeight;
}
기술면접

Answer 1

2

rookiss님의 프로필 이미지
rookiss
Instructor

로직은 정상 동작할 것 같지만,
사용하기 어려우니 굳이 전역으로 height, maxHeight를 관리할 이유가 없어 보입니다.

kangjaegoo167512's profile image
kangjaegoo167512

asked

Ask a question