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

atualizado

parent 7b80fde8
No related branches found
No related tags found
No related merge requests found
......@@ -15,10 +15,5 @@ class Node{
void setLeftNode(Node *newLeftNode);
void setRightNode(Node *newRightNode);
void setFatherNode(Node *newRatherNode);
int getKey();
char getTruck();
Node* getLeftNode();
Node* getRightNode();
Node* getFatherNode();
}
void printInOrder();
};
......@@ -2,7 +2,7 @@
// 2015
#include <iostream>
#include "bst_lib.h"
#include "lib/bst_lib.h"
using namespace std;
......@@ -22,28 +22,51 @@ void Node::setLeftNode(Node *newLeftNode){
void Node::setRightNode(Node *newRightNode){
rightNode=newRightNode;
}
void Node::setFatherNode(Node *newFatherNode){
fatherNode=newFatherNode;
}
int Node::getKey(){
return(this->key);
void Node::printInOrder(){
if(this->leftNode!=NULL){
this->leftNode.printInOrder()
}
char Node::getTruck(){
return(this->truck);
std::cout << " " << this->truck << this->key << " " << std::endl;
if(this->rightNode!=NULL){
this->rightNode.printInOrder();
}
Node* Node::getLeftNode(){
return(this->leftNode);
}
Node* Node::getRightNode(){
return(this->rightNode);
// Funções de manipulação da árvore
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(){
return(this->fatherNode);
void insertNode(Node *root, int key, char truck){
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