C++
- @Linda_pp
- 清楚なC++メイドBOT
- 長谷川一輝
- @jj1bdx
- 安藤敏彦
- Siv3D
- @hnokx
- @ishidakei
- TAKEI Yuya
- I (@wx257osn2)
- Tommy6
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
50
1
2
using namespace std;3
4
5
6
struct node{7
int data;8
node* left;9
node* right;10
};11
12
node* newNode(int item)13
14
{15
16
node* temp=new node();17
temp->data=item;18
temp->left=NULL;19
temp->right=NULL;20
return temp;21
22
23
}24
25
node* insertItem(node* root,int item){26
27
if(root==NULL){28
root= newNode(item);29
}30
31
else if(root->data>item){32
root->left=insertItem(root->left,item);33
34
}35
else if(root->data<item){36
root->right=insertItem(root->right,item);37
}38
return root;39
}40
41
int main(){42
43
node* root=NULL;44
root=insertItem(root,22);45
46
cout<<root->data;47
48
49
}50
$ g++ prog.cc -Wall -Wextra -std=c++98
Start
22
0
Finish