-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
12 tree #12
Open
jaeeunHwang
wants to merge
17
commits into
main
Choose a base branch
from
12_tree
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
12 tree #12
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
03b7a26
06_greedy_algorithm
jaeeunHwang c6a716b
231112 추가제출
jaeeunHwang 3575fc0
Merge branch '06_greedy_algorithm' of https://github.com/Altu-Bitu-5/…
jaeeunHwang ed9dee7
[투포인터] 11월 15일
jaeeunHwang 1a367bf
[투포인터] 11월 15일
jaeeunHwang 9b8f0d4
Delete 03_정수론/필수 directory
jaeeunHwang 262bb26
Delete 04_bruteforce directory
jaeeunHwang 4b18b47
Delete 06_greedy_algorithm/필수 directory
jaeeunHwang 20c844d
Delete 09_backtracking/필수 directory
jaeeunHwang b0edf41
Delete 10_binary_search directory
jaeeunHwang 7cce97f
231122 제출
jaeeunHwang 2c3e943
231122 제출
jaeeunHwang e5bdb0c
Delete 11-two-pointer directory
jaeeunHwang 38fb059
231122 제출
jaeeunHwang 3605b55
Merge branch '12_tree' of https://github.com/Altu-Bitu-5/Altu-Bitu-Hw…
jaeeunHwang 39e04c1
231122 제출
jaeeunHwang 2ad9455
231122 추가제출
jaeeunHwang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
// 이진 트리 노드 구조체 | ||
struct Node { | ||
int data; | ||
Node* left; | ||
Node* right; | ||
}; | ||
|
||
// 이진 트리 노드 생성 함수 | ||
Node* createNode(int data) { | ||
Node* newNode = new Node(); | ||
newNode->data = data; | ||
newNode->left = newNode->right = nullptr; | ||
return newNode; | ||
} | ||
|
||
// 이진 트리 삽입 함수 | ||
Node* insertNode(Node* root, int data) { | ||
if (root == nullptr) { | ||
return createNode(data); | ||
} | ||
|
||
if (data < root->data) { | ||
root->left = insertNode(root->left, data); | ||
} else { | ||
root->right = insertNode(root->right, data); | ||
} | ||
|
||
return root; | ||
} | ||
|
||
// 이진 트리 후위 순회 함수 | ||
void postorder(Node* root) { | ||
if (root == nullptr) { | ||
return; | ||
} | ||
|
||
postorder(root->left); | ||
postorder(root->right); | ||
cout << root->data << '\n'; | ||
} | ||
|
||
int main() { | ||
int value; | ||
Node* root = nullptr; | ||
|
||
//입력 & 연산 | ||
// 전위 순회 결과로 이진 트리 생성 | ||
while (cin >> value) { | ||
root = insertNode(root, value); | ||
} | ||
|
||
//출력 | ||
postorder(root); | ||
|
||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이진 트리를 먼저 만든 후에 후위 순회를 하는 방법으로 구현해 주셨습니다.👍 이 문제는 전위순회순서로부터 후위 순회 순서를 구하기만 하면 되므로, 이에 집중하여 전위 순회 순서를 입력받은 후 함수에서 이진 트리의 특성을 이용해서 후위 순회 순서를 바로 구하도록 할 수도 있답니다! 이 점도 고려해주시면 좋을 것 같아요!