cancio-labs/php-stack 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cancio-labs/php-stack

最新稳定版本:v1.2.1

Composer 安装命令:

composer require cancio-labs/php-stack

包简介

Interface and an array-based implementation of the LIFO Stack data structure.

README 文档

README

This tiny package contains an interface and an array-based implementation of the LIFO Stack data structure.

Interface

Method Description
push Adds a new element to the top of the stack.
pop Removes and return the top element of the stack.
top Returns the top element of the stack.
isEmpty Tests whether the stack is empty.
clear Removes all elements from the stack.
count Returns the number of elements of the stack.
toArray Transforms the stack into an array.

How to use it

$stack = new Stack(['A', 'B']);

$stack->push('C');
$stack->push('D');

$stack->isEmpty(); // returns false
$stack->count(); // returns 4

$stack->top(); // output 'D'
$stack->pop(); // returns 'D'

$array = $stack->toArray(); // return ['A', 'B', 'C']

foreach ($stack as $element) {
    // i=0: $element = 'C'
    // i=1: $element = 'B'
    // i=2: $element = 'A'
}

$stack->isEmpty(); // returns true 

Tests and Coverage

All tests are passing with no warnings and code coverage is 100%.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-02-27