Guest User

Untitled

a guest
Feb 13th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. 10
  2. /
  3. 6 14
  4. / /
  5. 5 8 11 18
  6.  
  7. #include "Board.h"
  8.  
  9. Board::Board(){
  10. newLength = 0;
  11. newScore = 0;
  12.  
  13. };
  14.  
  15. Board::~Board(){
  16.  
  17. };
  18.  
  19. Board::Board(btree b){
  20. newLength = NULL; //TO-DO : cantidad de nodos que tienen hojas PERO ¿cómo contarlos?
  21.  
  22. newScore = NULL; //TO-DO : número en el nodo actual PERO no sabemos de b que es el árbol actual.
  23.  
  24. moves = NULL;//TO-DO matriz de las posiciones izquierda y derecha de la corrientestate //node *left; and node *right;
  25.  
  26. };
  27.  
  28. // da la cantidad de hojas que podemos jugar: ya sea 2 o 0 en el caso del árbol binario.
  29. int board::legalMoves(moves)
  30. {
  31.  
  32. return NULL;
  33.  
  34. };
  35.  
  36. #include <iostream> //usefull ?
  37. #include <string> //usefull ?
  38. #include <vector>
  39.  
  40. #ifndef DEF_BOARD
  41. #define DEF_BOARD
  42.  
  43. class Board{
  44.  
  45. public:
  46. board();
  47. ~board();
  48.  
  49. //un Board está hecha de un árbol binario. Además, tiene una un score, una longitud
  50. board(btree);
  51.  
  52. //Y tiene posibles possibilidas
  53. legalMoves(moves)
  54.  
  55. private:
  56. //member variables
  57. int length;
  58. int score;
  59. // crear move? Matriz de las siguientes posibilidades: izquierda / derecha? O ninguno si estamos al final
  60. vector<int> tableau(2,NULL);
  61.  
  62. };
  63.  
  64. #endif
  65.  
  66. #define NULL 0
  67. #include "nestedSimple.c"
  68. #include "Board.h"
  69.  
  70. // main2
  71.  
  72. struct node
  73. {
  74. int key_value;
  75. node *left;
  76. node *right;
  77. };
  78.  
  79. class btree
  80. {
  81. public:
  82. btree();
  83. ~btree();
  84.  
  85. void insert(int key);
  86. node *search(int key);
  87. void destroy_tree();
  88.  
  89. private:
  90. void destroy_tree(node *leaf);
  91. void insert(int key, node *leaf);
  92. node *search(int key, node *leaf);
  93.  
  94. node *root;
  95. };
  96.  
  97. btree::btree()
  98. {
  99. root=NULL;
  100. }
  101.  
  102. btree::~btree()
  103. {
  104. destroy_tree();
  105. }
  106.  
  107. void btree::destroy_tree(node *leaf)
  108. {
  109. if(leaf!=NULL)
  110. {
  111. destroy_tree(leaf->left);
  112. destroy_tree(leaf->right);
  113. delete leaf;
  114. }
  115. }
  116.  
  117. void btree::insert(int key, node *leaf)
  118. {
  119. if(key< leaf->key_value)
  120. {
  121. if(leaf->left!=NULL)
  122. insert(key, leaf->left);
  123. else
  124. {
  125. leaf->left=new node;
  126. leaf->left->key_value=key;
  127. leaf->left->left=NULL; //Sets the left child of the child node to null
  128. leaf->left->right=NULL; //Sets the right child of the child node to null
  129. }
  130. }
  131. else if(key>=leaf->key_value)
  132. {
  133. if(leaf->right!=NULL)
  134. insert(key, leaf->right);
  135. else
  136. {
  137. leaf->right=new node;
  138. leaf->right->key_value=key;
  139. leaf->right->left=NULL; //Sets the left child of the child node to null
  140. leaf->right->right=NULL; //Sets the right child of the child node to null
  141. }
  142. }
  143. }
  144. void btree::insert(int key)
  145. {
  146. if(root!=NULL)
  147. insert(key, root);
  148. else
  149. {
  150. root=new node;
  151. root->key_value=key;
  152. root->left=NULL;
  153. root->right=NULL;
  154. }
  155. }
  156. node *btree::search(int key, node *leaf)
  157. {
  158. if(leaf!=NULL)
  159. {
  160. if(key==leaf->key_value)
  161. return leaf;
  162. if(key<leaf->key_value)
  163. return search(key, leaf->left);
  164. else
  165. return search(key, leaf->right);
  166. }
  167. else return NULL;
  168. }
  169.  
  170. node *btree::search(int key)
  171. {
  172. return search(key, root);
  173. }
  174.  
  175. void btree::destroy_tree()
  176. {
  177. destroy_tree(root);
  178. }
  179.  
  180. int main(int argc, char *argv []) {
  181. btree b;
  182. b.insert(5);
  183. b.insert(6);
  184. b.insert(8);
  185. b.insert(10);
  186. b.insert(11);
  187. b.insert(14);
  188. b.insert(18);
  189.  
  190. // create board with b
  191. board boa(b);
  192.  
  193. return(0);
  194. }
Add Comment
Please, Sign In to add comment