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

resolvido problema com virgula

parent 9b5d5d30
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -8,20 +8,20 @@ using namespace std; ...@@ -8,20 +8,20 @@ using namespace std;
class Node{ class Node{
private: private:
int key; int key;
string truck; char truck;
Node *leftNode; Node *leftNode;
Node *rightNode; Node *rightNode;
Node *fatherNode; Node *fatherNode;
public: public:
void setKey(int newKey); void setKey(int newKey);
void setTruck(string newTruck); void setTruck(char newTruck);
void setLeftNode(Node *newLeftNode); void setLeftNode(Node *newLeftNode);
void setRightNode(Node *newRightNode); void setRightNode(Node *newRightNode);
void setFatherNode(Node *newRatherNode); void setFatherNode(Node *newRatherNode);
int getKey(); int getKey();
string getTruck(); char getTruck();
Node* getLeftNode(); Node* getLeftNode();
Node* getRightNode(); Node* getRightNode();
Node* getFatherNode(); Node* getFatherNode();
...@@ -32,8 +32,8 @@ class Node{ ...@@ -32,8 +32,8 @@ class Node{
class Tree{ class Tree{
public: public:
Node *root; Node *root;
Node* createNode(int key, string truck, Node *father); Node* createNode(int key, char truck, Node *father);
Node* insertNode(int key, string truck, Node *father, Node *current); Node* insertNode(int key, char truck, Node *father, Node *current);
Node* binarySearch(int key, Node *current); Node* binarySearch(int key, Node *current);
}; };
......
No preview for this file type
No preview for this file type
...@@ -11,7 +11,7 @@ void Node::setKey(int newKey){ ...@@ -11,7 +11,7 @@ void Node::setKey(int newKey){
key=newKey; key=newKey;
} }
void Node::setTruck(string newTruck){ void Node::setTruck(char newTruck){
truck=newTruck; truck=newTruck;
} }
...@@ -31,7 +31,7 @@ int Node::getKey(){ ...@@ -31,7 +31,7 @@ int Node::getKey(){
return(key); return(key);
} }
string Node::getTruck(){ char Node::getTruck(){
return(truck); return(truck);
} }
...@@ -63,7 +63,7 @@ bool Node::printInOrder(){ ...@@ -63,7 +63,7 @@ bool Node::printInOrder(){
return 1; return 1;
} }
Node* Tree::createNode(int key, string truck, Node *father){ Node* Tree::createNode(int key, char truck, Node *father){
Node *aux=new Node; Node *aux=new Node;
aux->setKey(key); aux->setKey(key);
aux->setTruck(truck); aux->setTruck(truck);
...@@ -73,7 +73,7 @@ Node* Tree::createNode(int key, string truck, Node *father){ ...@@ -73,7 +73,7 @@ Node* Tree::createNode(int key, string truck, Node *father){
return aux; return aux;
} }
Node* Tree::insertNode(int key, string truck, Node *father, Node *current){ Node* Tree::insertNode(int key, char truck, Node *father, Node *current){
if(current==&nullNode){ if(current==&nullNode){
current=createNode(key, truck, father); current=createNode(key, truck, father);
}else if(current->getKey() > key){ }else if(current->getKey() > key){
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// 2015 // 2015
#include <iostream> #include <iostream>
#include <stdio.h>
#include "bst_lib.h" #include "bst_lib.h"
using namespace std; using namespace std;
...@@ -10,20 +11,13 @@ Node nullNode; ...@@ -10,20 +11,13 @@ Node nullNode;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Tree binaryTree; Tree binaryTree;
string answer, truck="ready"; char truck, comma1, comma2;
string answer;
int requestedTime, currentTime; int requestedTime, currentTime;
binaryTree.root=&nullNode; binaryTree.root=&nullNode;
while (1) { while (scanf("%d %c %c %c %d\n", &currentTime, &comma1, &truck, &comma2, &requestedTime)!=EOF) {
cin >> currentTime;
std::cin.clear();
cin >> truck;
if(truck=="exit") break;
if(truck == "print"){
binaryTree.root->printInOrder();
}else{
cin >> requestedTime;
if (requestedTime < currentTime) { if (requestedTime < currentTime) {
answer="NOK"; answer="NOK";
}else if((binaryTree.binarySearch(requestedTime, binaryTree.root) == &nullNode)&&(binaryTree.binarySearch(requestedTime-1, binaryTree.root) == &nullNode)&&(binaryTree.binarySearch(requestedTime-2, binaryTree.root) == &nullNode)){ }else if((binaryTree.binarySearch(requestedTime, binaryTree.root) == &nullNode)&&(binaryTree.binarySearch(requestedTime-1, binaryTree.root) == &nullNode)&&(binaryTree.binarySearch(requestedTime-2, binaryTree.root) == &nullNode)){
...@@ -32,9 +26,7 @@ int main(int argc, char *argv[]) { ...@@ -32,9 +26,7 @@ int main(int argc, char *argv[]) {
}else{ }else{
answer="NOK"; answer="NOK";
} }
cout << truck << "," << answer << endl;
} }
if(truck != "print") std::cout << truck << "," << answer << std::endl;
}
return 0; return 0;
} }
1 A 49 1,A,49
2 B 79 2,B,79
3 C 46 3,C,46
4 D 71 4,D,71
5 X 9 5,X,9
15 E 72 15,E,72
36 F 23 36,F,23
print
exit
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment