Skip to content
Snippets Groups Projects
Commit 5b4e3a5a authored by Eduardo Machado's avatar Eduardo Machado
Browse files

atualizado

parent 7b80fde8
Branches
No related tags found
No related merge requests found
...@@ -15,10 +15,5 @@ class Node{ ...@@ -15,10 +15,5 @@ class Node{
void setLeftNode(Node *newLeftNode); void setLeftNode(Node *newLeftNode);
void setRightNode(Node *newRightNode); void setRightNode(Node *newRightNode);
void setFatherNode(Node *newRatherNode); void setFatherNode(Node *newRatherNode);
void printInOrder();
int getKey(); };
char getTruck();
Node* getLeftNode();
Node* getRightNode();
Node* getFatherNode();
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// 2015 // 2015
#include <iostream> #include <iostream>
#include "bst_lib.h" #include "lib/bst_lib.h"
using namespace std; using namespace std;
...@@ -22,28 +22,51 @@ void Node::setLeftNode(Node *newLeftNode){ ...@@ -22,28 +22,51 @@ void Node::setLeftNode(Node *newLeftNode){
void Node::setRightNode(Node *newRightNode){ void Node::setRightNode(Node *newRightNode){
rightNode=newRightNode; rightNode=newRightNode;
} }
void Node::setFatherNode(Node *newFatherNode){ void Node::setFatherNode(Node *newFatherNode){
fatherNode=newFatherNode; fatherNode=newFatherNode;
} }
int Node::getKey(){ void Node::printInOrder(){
return(this->key); if(this->leftNode!=NULL){
this->leftNode.printInOrder()
} }
std::cout << " " << this->truck << this->key << " " << std::endl;
char Node::getTruck(){ if(this->rightNode!=NULL){
return(this->truck); this->rightNode.printInOrder();
} }
Node* Node::getLeftNode(){
return(this->leftNode);
} }
Node* Node::getRightNode(){ // Funções de manipulação da árvore
return(this->rightNode);
Node* createNode(int key, char truck){
Node *newNode=malloc(sizeof(Node));
newNode.setkey(key);
newNode.setTruck(truck);
newNode.setLeftNode(NULL);
newNode.setRightNode(NULL);
newNode.setFatherNode(NULL);
return(newNode);
} }
Node* Node::getFatherNode(){ void insertNode(Node *root, int key, char truck){
return(this->fatherNode); if(root==NULL){
root=createNode(key,truck);
}else if(root.key>key){
insertNode(root->leftNode);
}else if(root.key<key){
insertNode(root->rightNode);
}
} }
// Funções de manipulação da árvore Node* binarySearch(Node *root, int key){
if(root.key==key){
return(root);
}else if(root.key>key){
return(binarySearch(root->leftNode));
}else if(root.key<key){
return(binarySearch(root->rightNode));
}else if(root==NULL){
return (NULL);
}
}
// Implementado por Eduardo Machado
// 2015
#include <iostream>
#include "lib/bst_lib.h"
using namespace std;
int main(int argc, char *argv[]) {
Node *tree=NULL;
char *input, auxTruck;
int auxKey;
while (1) {
std::cin >> input;
if(strcmp(input,"insert")==0){
std::cin >> auxTruck;
std::cin >> auxKey;
if(binarySearch(tree,auxKey)!=NULL){
insertNode(tree,auxKey,auxTruck);
}
}else if(strcmp(input,"print")==0){
tree.printInOrder;
}
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment