Stack.class.php 1.5 KB

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