stack.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*!
  2. Temelia - Stack interface.
  3. Copyright (C) 2008, 2009 Ceata (http://cod.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. #ifndef STACK_H_
  18. #define STACK_H_
  19. #include "platform.h"
  20. struct _stack_t;
  21. typedef struct _stack_t *stack_t;
  22. /*!
  23. * @brief Constructor - allocates an empty stack with maximum N keys.
  24. * Complexity O(1)
  25. *
  26. * @param Stack'stack size
  27. */
  28. DECLSPEC stack_t stack_new(int capacity);
  29. /*!
  30. * @brief Destructor - frees the memory occuppied by the stack.
  31. * Complexity O(n)
  32. *
  33. * @param Stack
  34. */
  35. DECLSPEC void stack_delete(stack_t stack);
  36. /*!
  37. * @brief Returns the current number of keys of the given stack.
  38. * Complexity O(1)
  39. *
  40. * @param Stack
  41. */
  42. DECLSPEC int stack_get_size(stack_t stack);
  43. /*!
  44. * @brief Returns the maximum number of keys of the given stack.
  45. * Complexity O(1)
  46. *
  47. * @param Stack
  48. */
  49. DECLSPEC int stack_get_capacity(stack_t stack);
  50. /*!
  51. * @brief Returns the current capacity increment, when the stack
  52. * will be full.
  53. * Complexity O(1)
  54. *
  55. * @param Stack
  56. */
  57. DECLSPEC int stack_get_capacity_increment(stack_t stack);
  58. /*!
  59. * @brief Sets the capacity increment step, when the stack gets full.
  60. * Complexity O(1)
  61. *
  62. * @param Stack
  63. * @param Capacity increment value
  64. */
  65. DECLSPEC void stack_set_capacity_increment(stack_t stack, int new_capacity_increment);
  66. /*!
  67. * @brief Returns the internal stack representation; cast it to vector.
  68. * Complexity O(1)
  69. *
  70. * @param Stack
  71. */
  72. DECLSPEC void *stack_get_internal_representation(stack_t stack);
  73. /*!
  74. * @brief Returns 1 if the stack is empty and 0 if it isn't.
  75. * Complexity O(1)
  76. *
  77. * @param Stack
  78. */
  79. DECLSPEC int stack_is_empty(stack_t stack);
  80. /*!
  81. * @brief Returns 1 if the stack is full and 0 if it isn't.
  82. * Complexity O(1)
  83. *
  84. * @param Stack
  85. */
  86. DECLSPEC int stack_is_full(stack_t stack);
  87. /*!
  88. * @brief Pushes key into the stack.
  89. * Complexity O(1)
  90. *
  91. * @param Stack
  92. * @param Key
  93. */
  94. DECLSPEC void stack_push(stack_t stack, void *key);
  95. /*!
  96. * @brief Removes key from stack'stack peek.
  97. * Complexity O(1)
  98. *
  99. * @param Stack
  100. */
  101. DECLSPEC void stack_pop(stack_t stack);
  102. /*!
  103. * @brief Returns the key from the peek of the stack.
  104. * Complexity O(1)
  105. *
  106. * @param Stack
  107. */
  108. DECLSPEC void *stack_top(stack_t stack);
  109. /*!
  110. * @brief Iterates over the keys of the stack . If order is 1 the functions prints
  111. * the keys in the natural order (LIFO) , else if order is -1 the functions
  112. * prints the keys in the same order you introduced them.
  113. * Complexity O(n)
  114. *
  115. * @param Stack
  116. * @param Pointer to iterating function
  117. * @param Context
  118. * @param Order
  119. */
  120. DECLSPEC void stack_iterate(stack_t stack, void key_handler(void *key, void *context),
  121. void *context, int order);
  122. #endif /* STACK_H_ */