์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- ํฌ๋ํํค์ ๊ธ4๊ธฐ
- ํฌ๋ํํค์ ๊ธ
- ์ฐ๊ฒฐ๋ฆฌ์คํธ
- project3
- ์ถ์ํด๋์ค์์ธํฐํ์ด์ค
- ๋คํธ์ํฌ
- ๋ค์ต์คํธ๋ผ
- ํฌ๋ํํค ์ ๊ธ
- ์ค๋ธ์
- ์ ์-์ ํฌ
- kraftonjungle
- 4๊ธฐ
- ์ด๋ฒคํธ ํจ์ ์คํ ์์
- ์ ๋ํฐ
- ํฐ์คํ ๋ฆฌ์ฑ๋ฆฐ์ง
- C
- pintos
- User Stack
- ํํ ์ค
- TiL
- anonymous page
- ์๊ณ ๋ฆฌ์ฆ์์ -๋๋น์ฐ์ ํ์2
- ํฌ๋ํํค ์ ๊ธ 4๊ธฐ
- KRAFTON JUNGLE
- ๋ฐฑ์ค
- ํ์ด์ฌ
- ์๊ณ ๋ฆฌ์ฆ
- BFS
- Unity
- c#
Archives
- Today
- Total
๋ง๊ฐ๋ก๊ทธ
ํฌ๋ํํค ์ ๊ธ WEEK5 Day37 - Binary Tree ๋ณธ๋ฌธ
728x90
๐2024.2.13
์ค๋ Binary Tree ๊ณผ์ ๋ค ํ์๋ค......
๋ชจ๋ ๋ฌธ์ ๊ฐ ์ฌ๊ท๋ก ํธ๋ ํ์์ด๋ผ ์ ๊ทผ๋ฐฉ์์ ๋ค ๋น์ทํด์ ๊ธ๋ฐฉ ํ ์ ์์๋ค.
๊ทธ๋ฆฌ๊ณ ์ด์ ์คํ ํ๋ฉด์ ๋ดค๋ ๊ดํธ ๋ฌธ์ ์ฐพ์์ ๋ฐฑ์ค ๊ดํธ ๋ฌธ์ ํ๊ณ , ํ๋ก๊ทธ๋๋จธ์ค ์ฝ๋ฉ ๊ธฐ์ด ํธ๋ ์ด๋ ์บ๋ฆฐ๋ ๋์ฅ ๊นจ๊ธฐ ํ๊ณ ์๋ค. ๋ด์ผ์ BST ๋ค ํ๊ณ ์ฑ ,ํค์๋ ๊ณต๋ถํด์ผ๊ฒ ๋ค!
Binary Tree
identical
๋ ๊ฐ์ ์ด์ง ํธ๋ฆฌ๊ฐ ๊ตฌ์กฐ์ ์ผ๋ก ๋์ผํ์ง ํ๋ณ
int identical(BTNode *tree1, BTNode *tree2)
{
/* add your code here */
if(tree1 == NULL && tree2 == NULL) //๋ ํธ๋ฆฌ๊ฐ ๋ชจ๋ ๋น์ด์์ผ๋ฉด ๋์ผํ๋ค๊ณ ํ๋จ
return 1;
else if(tree1 != NULL && tree2 != NULL){
return(
tree1->item == tree2->item &&
identical(tree1->left, tree2->left) &&
identical(tree1->right,tree2->right)
);
}
else
return 0;
}
maxHeight
์ฌ๊ท ์ด์ฉํด์ ์ต๋ ๋์ด ๋ํ๋
int maxHeight(BTNode *node)
{
/* add your code here */
if(node == NULL) return -1;
else
{
int l = maxHeight(node->left);
int r = maxHeight(node->right);
if(l > r) return l + 1;
else return r + 1;
}
}
countOneChildNodes
์ฌ๊ท๋ฅผ ์ด์ฉํด์ ํ์์ธ ๋ ธ๋์ ํฉ์ ๊ตฌํด๋ผ
int sumOfOddNodes(BTNode *node)
{
/* add your code here */
if(node == NULL) return 0;
else if(node->item % 2 == 1)
{
return sumOfOddNodes(node->left) + sumOfOddNodes(node->right) + node->item;
}
else
return sumOfOddNodes(node->left) + sumOfOddNodes(node->right);
}
mirrorTree
void mirrorTree(BTNode *node)
{
/* add your code here */
if(node == NULL) return;
else
{
//ํ์ฌ ๋
ธ๋์ ์ผ์ชฝ ์๋ธํธ๋ฆฌ์ ์ค๋ฅธ์ชฝ ์๋ธํธ๋ฆฌ ์ค์
BTNode *temp;
temp = node->left;
node->left = node->right;
node->right = temp;
mirrorTree(node->left);
mirrorTree(node->right);
}
}
printSmallerValues
void printSmallerValues(BTNode *node, int m)
{
/* add your code here */
if(node == NULL) return;
else
{
if(node->item < m)
{
printf("%d ", node->item);
}
//์ผ์ชฝ ์ค๋ฅธ์ชฝ ์๋ธํธ๋ฆฌ ๋ชจ๋ ํ์
printSmallerValues(node->left, m);
printSmallerValues(node->right,m);
}
}
smallestValue
int smallestValue(BTNode *node)
{
/* add your code here */
if(node == NULL) return -1;
else if(node->left == NULL && node->right == NULL)
return node->item;
else
{
int leftsmall = smallestValue(node->left);
int rightsmall = smallestValue(node->right);
if(leftsmall > rightsmall)
return rightsmall;
else
return leftsmall;
}
}
hasGreatGrandchild
int hasGreatGrandchild(BTNode *node)
{
/* add your code here */
if(node == NULL) return -1;
else
{
int l = hasGreatGrandchild(node->left);
int r = hasGreatGrandchild(node->right);
if(l + 1 > 2 || r + 1 > 2)
printf("%d ", node->item);
return ((l > r) ? l : r ) + 1;
}
}
728x90
'Krafton jungle' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํฌ๋ํํค ์ ๊ธ WEEK5 Day 39 - ๊ฐ์๋ฉ๋ชจ๋ฆฌ (0) | 2024.02.15 |
---|---|
ํฌ๋ํํค ์ ๊ธ WEEK5 Day 38 -BST (0) | 2024.02.15 |
ํฌ๋ํํค ์ ๊ธ WEEK5 Day 36 - Stack and Queue (0) | 2024.02.13 |
ํฌ๋ํํค ์ ๊ธ WEEK5 Day 35 (1) | 2024.02.12 |
ํฌ๋ํํค ์ ๊ธ WEEK5 Day 34 (2) | 2024.02.11 |