Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 10
- /
- 6 14
- / /
- 5 8 11 18
- #include "Board.h"
- Board::Board(){
- newLength = 0;
- newScore = 0;
- };
- Board::~Board(){
- };
- Board::Board(btree b){
- newLength = NULL; //TO-DO : cantidad de nodos que tienen hojas PERO ¿cómo contarlos?
- newScore = NULL; //TO-DO : número en el nodo actual PERO no sabemos de b que es el árbol actual.
- moves = NULL;//TO-DO matriz de las posiciones izquierda y derecha de la corrientestate //node *left; and node *right;
- };
- // da la cantidad de hojas que podemos jugar: ya sea 2 o 0 en el caso del árbol binario.
- int board::legalMoves(moves)
- {
- return NULL;
- };
- #include <iostream> //usefull ?
- #include <string> //usefull ?
- #include <vector>
- #ifndef DEF_BOARD
- #define DEF_BOARD
- class Board{
- public:
- board();
- ~board();
- //un Board está hecha de un árbol binario. Además, tiene una un score, una longitud
- board(btree);
- //Y tiene posibles possibilidas
- legalMoves(moves)
- private:
- //member variables
- int length;
- int score;
- // crear move? Matriz de las siguientes posibilidades: izquierda / derecha? O ninguno si estamos al final
- vector<int> tableau(2,NULL);
- };
- #endif
- #define NULL 0
- #include "nestedSimple.c"
- #include "Board.h"
- // main2
- struct node
- {
- int key_value;
- node *left;
- node *right;
- };
- class btree
- {
- public:
- btree();
- ~btree();
- void insert(int key);
- node *search(int key);
- void destroy_tree();
- private:
- void destroy_tree(node *leaf);
- void insert(int key, node *leaf);
- node *search(int key, node *leaf);
- node *root;
- };
- btree::btree()
- {
- root=NULL;
- }
- btree::~btree()
- {
- destroy_tree();
- }
- void btree::destroy_tree(node *leaf)
- {
- if(leaf!=NULL)
- {
- destroy_tree(leaf->left);
- destroy_tree(leaf->right);
- delete leaf;
- }
- }
- void btree::insert(int key, node *leaf)
- {
- if(key< leaf->key_value)
- {
- if(leaf->left!=NULL)
- insert(key, leaf->left);
- else
- {
- leaf->left=new node;
- leaf->left->key_value=key;
- leaf->left->left=NULL; //Sets the left child of the child node to null
- leaf->left->right=NULL; //Sets the right child of the child node to null
- }
- }
- else if(key>=leaf->key_value)
- {
- if(leaf->right!=NULL)
- insert(key, leaf->right);
- else
- {
- leaf->right=new node;
- leaf->right->key_value=key;
- leaf->right->left=NULL; //Sets the left child of the child node to null
- leaf->right->right=NULL; //Sets the right child of the child node to null
- }
- }
- }
- void btree::insert(int key)
- {
- if(root!=NULL)
- insert(key, root);
- else
- {
- root=new node;
- root->key_value=key;
- root->left=NULL;
- root->right=NULL;
- }
- }
- node *btree::search(int key, node *leaf)
- {
- if(leaf!=NULL)
- {
- if(key==leaf->key_value)
- return leaf;
- if(key<leaf->key_value)
- return search(key, leaf->left);
- else
- return search(key, leaf->right);
- }
- else return NULL;
- }
- node *btree::search(int key)
- {
- return search(key, root);
- }
- void btree::destroy_tree()
- {
- destroy_tree(root);
- }
- int main(int argc, char *argv []) {
- btree b;
- b.insert(5);
- b.insert(6);
- b.insert(8);
- b.insert(10);
- b.insert(11);
- b.insert(14);
- b.insert(18);
- // create board with b
- board boa(b);
- return(0);
- }
Add Comment
Please, Sign In to add comment