강의

멘토링

커뮤니티

Inflearn コミュニティ Q&A

kimpran のプロフィール画像
kimpran

投稿した質問数

絵でわかる データ構造とアルゴリズム (発展編)

優先順位キューとヒープ - 実装1(ヒープ挿入)

else if 질문 있습니다.

解決済みの質問

作成

·

351

1

힙 삽입에서

getInsertingParent(){
        if(this.lastInsertedNode.getParent() == null){
            return this.lastInsertedNode;
        }else{
            if(this.lastInsertedNode == this.lastInsertedNode.getParent().getLeftSubTree()){
                return this.lastInsertedNode.getParent();
            }else{
                let current = this.lastInsertedNode;
                let firstRightSibling = null;

                while(current.getParent().getParent() != null){
                    current = current.getParent();

                    firstRightSibling = this.getRightSibling(current);
                    if(firstRightSibling != null){
                        break;
                    }
                }

마지막으로 삽입된 노드가 루트노드일때를 if문으로 처리하시고 그다음 else 안에 서 if문으로 다시 처리하셨는데 이유가 있을까요? else if로 안쓰시고 else 안에서 if를 쓰신 이유가 궁금합니다..!!

알고리즘algorithm

回答 2

1

kimpran님의 프로필 이미지
kimpran
質問者

네!! 답변 감사합니다.

0

gamja5님의 프로필 이미지
gamja5
インストラクター

가독성을 위해서 나눠서 작성했습니다!
로직만 같다면 편하신 걸 선택하시면 될 것 같습니다 ㅎㅎ

kimpran のプロフィール画像
kimpran

投稿した質問数

質問する