From 5b4e3a5a9daa43a2f82f8668d8b574ad626473d0 Mon Sep 17 00:00:00 2001
From: Eduardo Machado <emm14@inf.ufpr.br>
Date: Tue, 29 Sep 2015 17:28:52 -0300
Subject: [PATCH] atualizado

---
 lib/bst_lib.h   |  9 ++-------
 src/bst_lib.cpp | 51 +++++++++++++++++++++++++++++++++++--------------
 src/main.cpp    | 28 +++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 21 deletions(-)
 create mode 100644 src/main.cpp

diff --git a/lib/bst_lib.h b/lib/bst_lib.h
index 4a4c4b1..2aeccba 100644
--- a/lib/bst_lib.h
+++ b/lib/bst_lib.h
@@ -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();
+};
diff --git a/src/bst_lib.cpp b/src/bst_lib.cpp
index 19eff2a..0164a33 100644
--- a/src/bst_lib.cpp
+++ b/src/bst_lib.cpp
@@ -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()
+  }
+  std::cout << " " << this->truck << this->key << " " << std::endl;
+  if(this->rightNode!=NULL){
+    this->rightNode.printInOrder();
+  }
 }
 
-char Node::getTruck(){
-  return(this->truck);
-}
+// Funções de manipulação da árvore
 
-Node* Node::getLeftNode(){
-  return(this->leftNode);
+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::getRightNode(){
-  return(this->rightNode);
+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);
+  }
 }
 
-Node* Node::getFatherNode(){
-  return(this->fatherNode);
+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);
+  }
 }
-
-// Funções de manipulação da árvore
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..eeb0ff4
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,28 @@
+// 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;
+}
-- 
GitLab