-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarytree.cpp
More file actions
107 lines (84 loc) · 1.9 KB
/
Copy pathbinarytree.cpp
File metadata and controls
107 lines (84 loc) · 1.9 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <iostream>
using namespace std;
struct nodeTree {
int key;
nodeTree *left;
nodeTree *right;
};
nodeTree * newNode(int value){
nodeTree *node=new nodeTree;
node->key=value;
node->left=NULL;
node->right=NULL;
return (node);
}
//search
bool searchNoRecursion(nodeTree *leaf, int key){
bool found=false;
//use a while loop and not recursion. Leaf is being changed
//each and every time to point to the left or right, going down
//the tree.
while (leaf!=NULL && !found){
if (key==leaf->key){
found=true;
}else if (key < leaf->key)
leaf=leaf->left; //replaces recursion
else
leaf=leaf->right;
}
return found;
}
//insert
nodeTree * insertNoRecursion(nodeTree *leaf, int key){
bool foundSpot=false;
while (leaf!=NULL && !foundSpot){
if (key==leaf->key)
leaf=NULL; //no need to insert
//If it is smaller, then go to the left
else if (key < leaf->key)
if (leaf->left !=NULL)
leaf=leaf->left;
else
foundSpot=true;
else{
if (leaf->right!=NULL)
leaf=leaf->right;
else
foundSpot=true;
}
}
return leaf;
}
//del
void deleteNode (nodeTree *leaf, int delVal)
{
}
int main( ){
struct nodeTree *root;
FILE *in1, *out;
in1=fopen("input.txt", "r");
int data;
int delVal=1;
while(true)
{
searchNoRecursion(root, data);
insertNoRecursion(root,data);
if (searchNoRecursion==false)
{
deleteNode (root, delVal);
}
}
//node *left1;
//node *right1;
root=NULL;
/*
while(in.good())
{
in1>> data;
}
*/
}