Stack

Basic Stack Class.

Defined (1)

The class is defined in the following location(s).

/includes/Libraries/EOS/Stack.php  
  1. class Stack { 
  2. private $index; 
  3. private $locArray; 
  4.  
  5. /** 
  6. * Constructor 
  7. * Initializes the stack 
  8. */ 
  9. public function __construct() { 
  10. //define the private vars 
  11. $this->locArray = array(); 
  12. $this->index = -1; 
  13.  
  14. /** 
  15. * Peek 
  16. * Will view the last element of the stack without removing it 
  17. * @return Mixed An element of the array or false if none exist 
  18. */ 
  19. public function peek() { 
  20. if($this->index > -1) 
  21. return $this->locArray[$this->index]; 
  22. else 
  23. return false; 
  24.  
  25. /** 
  26. * Poke 
  27. * Will add an element to the end of the stack 
  28. * @param Mixed $data Element to add 
  29. */ 
  30. public function poke($data) { 
  31. $this->locArray[++$this->index] = $data; 
  32.  
  33. /** 
  34. * Push 
  35. * Alias of {@see Stack::poke()} 
  36. * Adds element to the stack 
  37. * @param Mixed $data Element to add 
  38. */ 
  39. public function push($data) { 
  40. //allias for 'poke' 
  41. $this->poke($data); 
  42.  
  43. /** 
  44. * Pop 
  45. * Retrives an element from the end of the stack, and removes it from 
  46. * the stack at the same time. If no elements, returns boolean false 
  47. * @return Mixed Element at end of stack or false if none exist 
  48. */ 
  49. public function pop() { 
  50. if($this->index > -1) 
  51. $this->index--; 
  52. return $this->locArray[$this->index+1]; 
  53. else 
  54. return false; 
  55.  
  56. /** 
  57. * Clear 
  58. * Clears the stack to be reused. 
  59. */ 
  60. public function clear() { 
  61. $this->index = -1; 
  62. $this->locArray = array(); 
  63.  
  64. /** 
  65. * Get Stack 
  66. * Returns the array of stack elements, keeping all, indexed at 0 
  67. * @return Mixed Array of stack elements or false if none exist. 
  68. */ 
  69. public function getStack() { 
  70. if($this->index > -1) 
  71. return array_values($this->locArray); 
  72. else 
  73. return false;