diff --git a/bst b/bst index 0e3c369d4c667788070552a114119fcfdd9a2ce5..ae82def670b7145618b319007006307ae9fc2d26 100755 Binary files a/bst and b/bst differ diff --git a/include/bst_lib.h b/include/bst_lib.h index ea0ac21edbe706f65d2bb2332c91c869f96f21dd..97e8296e8f700607f2fbdaf1ae8ec4b8d46f0f61 100644 --- a/include/bst_lib.h +++ b/include/bst_lib.h @@ -33,7 +33,7 @@ class Tree{ public: Node *root; Node* createNode(int key, string truck, Node *father); - bool insertNode(int key, string truck, Node *father, Node *current); + Node* insertNode(int key, string truck, Node *father, Node *current); Node* binarySearch(int key, Node *current); }; diff --git a/lib/bst_lib.a b/lib/bst_lib.a index e710adc24ebdba929d6daf0dc2190841880c5eff..d4140fc2afb62a284a77592ffb58011e73e59bc4 100644 Binary files a/lib/bst_lib.a and b/lib/bst_lib.a differ diff --git a/obj/bst_lib.o b/obj/bst_lib.o index 3f98ad5bf4906bff78aa5262671b3d57b94c5481..c48485e11d20846c2ffbbfee518e3df709619a17 100644 Binary files a/obj/bst_lib.o and b/obj/bst_lib.o differ diff --git a/src/bst_lib.cpp b/src/bst_lib.cpp index 4f10ae302a0a94920e1342e0bfb06c559ad2bfe2..2551d46eb84dddd345f77df040d70d261a57b524 100644 --- a/src/bst_lib.cpp +++ b/src/bst_lib.cpp @@ -82,7 +82,7 @@ Node* Tree::createNode(int key, string truck, Node *father){ return aux; } -bool Tree::insertNode(int key, string truck, Node *father, Node *current){ +Node* Tree::insertNode(int key, string truck, Node *father, Node *current){ if(current==&nullNode){ std::cout << "insertNode - 1" << std::endl; cout << current << endl; @@ -90,15 +90,15 @@ bool Tree::insertNode(int key, string truck, Node *father, Node *current){ cout << current << endl; }else if(current->getKey() > key){ std::cout << "insertNode - 2" << std::endl; - insertNode(key, truck, current, current->getLeftNode()); + current->setLeftNode(insertNode(key, truck, current, current->getLeftNode())); }else if(current->getKey() < key){ std::cout << "insertNode - 3" << std::endl; - insertNode(key, truck, current, current->getRightNode()); + current->setRightNode(insertNode(key, truck, current, current->getRightNode())); }else{ std::cout << "Chave ocupada!" << std::endl; - return 0; + return &nullNode; } - return 1; + return current; } Node* Tree::binarySearch(int key, Node *current){ diff --git a/src/main.cpp b/src/main.cpp index 0f4d7548b8c97970ec099ed230291f7139372af6..0ec1268c1047eccb2c13c53f97063d36ef9dfc53 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) { cin >> auxKey; if(binaryTree.binarySearch(auxKey, binaryTree.root) == &nullNode){ cout << binaryTree.root << endl; - binaryTree.insertNode(auxKey, auxTruck, &nullNode, binaryTree.root); + binaryTree.root=binaryTree.insertNode(auxKey, auxTruck, &nullNode, binaryTree.root); cout << binaryTree.root << endl; } }else if(input == "print"){