-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrzewoBinarne.cpp
More file actions
54 lines (51 loc) 路 1.24 KB
/
Copy pathDrzewoBinarne.cpp
File metadata and controls
54 lines (51 loc) 路 1.24 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Created by kukul on 21.11.2019.
//
#include "DrzewoBinarne.h"
#include "Lista.h"
#include <iostream>
using namespace std;
void DrzewoBinarne::add(int x, node *&korzen) {
node* newNode = new node;
node* current = korzen;
node* parent=NULL;
newNode->left = NULL;
newNode->right = NULL;
newNode->data = x;
if(korzen == NULL){
korzen = newNode;
}else{
parent = current;
while(true){
if(x <= parent->data){
current = current->left;
if(current == NULL){
parent->left = newNode;
return;
}
}else{
current = current->right;
if(current == NULL){
parent->right = newNode;
return;
}
}
}
}
}
int DrzewoBinarne::search(int x, node *korzen) {
if(korzen==NULL){
cout<<"Puste drzewo"<<endl;
} else {
node* current = korzen;
while(current->data!=x){
if (x<current->data){
current = current->left;
}else if(x>current->data){
current = current->right;
}else{
}
}
}
return 0;
}