Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node
- {
- int data;
- struct Node* left, * right;
- Node(int data)
- {
- this->data = data;
- left = right = NULL;
- }
- };
- int src(Node *root,int idata) {
- if (root == NULL)
- return NULL;
- if (idata == root->data) {
- cout << "Pronaden: "<< root->data;
- return root->data;
- }
- if (idata < root->data) {
- return src(root->left, idata);
- }
- if (idata > root->data) {
- return src(root->right, idata);
- }
- }
- int main() {
- struct Node* root = new Node(50);
- root->left = new Node(17);
- root->right = new Node(72);
- root->left->left = new Node(12);
- root->left->right = new Node(23);
- root->right->left = new Node(54);
- root->right->right = new Node(76);
- root->left->left->left = new Node(9);
- root->left->left->right = new Node(14);
- root->left->right->left = new Node(19);
- root->right->left->right = new Node(67);
- int idata;
- cout << "Trazena vrijednost: ";
- cin >> idata;
- src(root, idata);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement