binary_search_tree.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*!
  2. Temelia - Binary search tree implementation source file.
  3. Copyright (C) 2008, 2009 Ceata (http://ceata.org/proiecte/temelia).
  4. @author Dascalu Laurentiu
  5. This program is free software; you can redistribute it and
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 3
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #include "include/binary_search_tree.h"
  18. /*!
  19. * All the functions are wrappers, one to one calls, over the private
  20. * functions from the binary_tree_common.h header.
  21. */
  22. binary_search_tree_t binary_search_tree_new(void *key)
  23. {
  24. return _binary_tree_new(key);
  25. }
  26. void binary_search_tree_delete_node(binary_search_tree_node_t node)
  27. {
  28. _binary_tree_delete_node(node);
  29. }
  30. void binary_search_tree_delete(binary_search_tree_t bst)
  31. {
  32. _binary_tree_delete(bst);
  33. }
  34. int binary_search_tree_empty(binary_search_tree_t bst)
  35. {
  36. return _binary_tree_is_empty(bst);
  37. }
  38. int binary_search_tree_leaf(binary_search_tree_t bst)
  39. {
  40. return _binary_tree_leaf(bst);
  41. }
  42. int binary_search_tree_get_size(binary_search_tree_t bst)
  43. {
  44. return _binary_tree_get_size(bst);
  45. }
  46. binary_search_tree_t binary_search_tree_get_root(binary_search_tree_node_t node)
  47. {
  48. return _binary_tree_get_root(node);
  49. }
  50. void *binary_search_tree_get_key(binary_search_tree_node_t node)
  51. {
  52. return _binary_tree_get_key(node);
  53. }
  54. binary_search_tree_node_t binary_search_tree_get_parent(
  55. binary_search_tree_node_t node)
  56. {
  57. return _binary_tree_get_parent(node);
  58. }
  59. binary_search_tree_node_t binary_search_tree_get_left_child(
  60. binary_search_tree_node_t node)
  61. {
  62. return _binary_tree_get_left_child(node);
  63. }
  64. binary_search_tree_node_t binary_search_tree_get_right_child(
  65. binary_search_tree_node_t node)
  66. {
  67. return _binary_tree_get_right_child(node);
  68. }
  69. void binary_search_tree_split(binary_search_tree_t parent,
  70. binary_search_tree_t *left, binary_search_tree_t *right)
  71. {
  72. _binary_tree_split(parent, left, right);
  73. }
  74. int binary_search_tree_get_height(binary_search_tree_t tree)
  75. {
  76. return _binary_tree_get_height(tree);
  77. }
  78. int binary_search_tree_get_depth(binary_search_tree_node_t node)
  79. {
  80. return _binary_tree_get_depth(node);
  81. }
  82. binary_search_tree_node_t binary_search_tree_search(binary_search_tree_t bst,
  83. void *key, int compare(void *x, void *y, void *context), void *context)
  84. {
  85. return _binary_search_tree_search(bst, key, compare, context);
  86. }
  87. binary_search_tree_node_t binary_search_tree_insert(binary_search_tree_t bst,
  88. void *key, int compare(void *x, void *y, void *context), void *context)
  89. {
  90. return _binary_search_tree_insert(bst, key, compare, context);
  91. }
  92. binary_search_tree_node_t binary_search_tree_remove(binary_search_tree_t *bst,
  93. void *key, int compare(void *x, void *y, void *context), void *context,
  94. binary_search_tree_t *freed)
  95. {
  96. return _binary_search_tree_remove(bst, key, compare, context, freed);
  97. }
  98. binary_search_tree_node_t binary_search_tree_get_min(binary_search_tree_t bst)
  99. {
  100. return _binary_search_tree_get_min(bst);
  101. }
  102. binary_search_tree_node_t binary_search_tree_get_max(binary_search_tree_t bst)
  103. {
  104. return _binary_search_tree_get_max(bst);
  105. }
  106. binary_search_tree_node_t binary_search_tree_next(binary_search_tree_t bst,
  107. binary_search_tree_node_t node)
  108. {
  109. return _binary_search_tree_next(bst, node);
  110. }
  111. binary_search_tree_node_t binary_search_tree_prev(binary_search_tree_t bst,
  112. binary_search_tree_node_t node)
  113. {
  114. return _binary_search_tree_prev(bst, node);
  115. }
  116. void binary_search_tree_preorder(binary_search_tree_t tree, void key_handler(
  117. void *x, void *context), void *context)
  118. {
  119. _binary_tree_preorder(tree, key_handler, context);
  120. }
  121. void binary_search_tree_inorder(binary_search_tree_t tree, void key_handler(
  122. void *x, void *context), void *context)
  123. {
  124. _binary_tree_inorder(tree, key_handler, context);
  125. }
  126. void binary_search_tree_reverse_inorder(binary_search_tree_t tree,
  127. void key_handler(void *x, void *context), void *context)
  128. {
  129. _binary_tree_reverse_inorder(tree, key_handler, context);
  130. }
  131. void binary_search_tree_postorder(binary_search_tree_t tree, void key_handler(
  132. void *x, void *context), void *context)
  133. {
  134. _binary_tree_postorder(tree, key_handler, context);
  135. }
  136. void binary_search_tree_level_order(binary_search_tree_t tree, void key_handler(
  137. void *x, void *context), void *context)
  138. {
  139. _binary_tree_level_order(tree, key_handler, context);
  140. }
  141. void binary_search_tree_show_indented(binary_search_tree_t tree,
  142. void key_handler(void *key, int level, void *context), void *context)
  143. {
  144. _binary_tree_show_indented(tree, key_handler, context, 0);
  145. }