Stack.class.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: liu21st <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. namespace Org\Util;
  12. /**
  13. * Stack实现类
  14. * @category ORG
  15. * @package ORG
  16. * @subpackage Util
  17. * @author liu21st <liu21st@gmail.com>
  18. */
  19. class Stack extends ArrayList {
  20. /**
  21. * 架构函数
  22. * @access public
  23. * @param array $values 初始化数组元素
  24. */
  25. public function __construct($values = array()) {
  26. parent::__construct($values);
  27. }
  28. /**
  29. * 将堆栈的内部指针指向第一个单元
  30. * @access public
  31. * @return mixed
  32. */
  33. public function peek() {
  34. return reset($this->toArray());
  35. }
  36. /**
  37. * 元素进栈
  38. * @access public
  39. * @param mixed $value
  40. * @return mixed
  41. */
  42. public function push($value) {
  43. $this->add($value);
  44. return $value;
  45. }
  46. }