当前位置:网站首页>Stack, LIFO
Stack, LIFO
2022-06-26 13:21:00 【liuliang514218119】
<?php
# After the first out Stack
class stack
{
public $data = [];
public $size;
public function __construct($size = 10)
{
$this->size = $size;
}
# Push
public function push($element)
{
if (count($this->data) >= $this->size) {
throw new Exception(" The stack is full ");
return " The stack is full ";
}
array_push($this->data, $element);
}
# Out of the stack
public function pop()
{
if (count($this->data) < 1) {
throw new Exception(" The stack is empty. ");
return " The stack is empty. ";
}
return array_pop($this->data);
}
# To the top of the stack
public function get_top()
{
if (count($this->data) < 1) {
throw new Exception(" The stack is empty. ");
return " The stack is empty. ";
}
return end($this->data); # Internal pointer to the last element in the array
}
public function get_data()
{
return $this->data;
}
}
// Declaration stack
$stack = new stack();
$stack->push(5);
$stack->push(6);
$stack->push(7);
$stack->push(8);
$stack->push(9);
$stack->pop();
print_r($stack->get_top());
echo "\n";
print_r($stack->get_data());
die;
边栏推荐
- 利用scrapy爬取句子迷网站优美句子存储到本地(喜欢摘抄的人有福了!)
- HDU1724[辛普森公式求积分]Ellipse
- Sinotech software outsourcing
- Word document export (using fixed template)
- 橋接模式(Bridge)
- UVA5009 Error Curves三分
- [how to connect the network] Chapter 2 (Part 1): establish a connection, transmit data, and disconnect
- J - Wooden Sticks poj 1065
- 解中小企业之困,百度智能云打个样
- Explain C language 10 in detail (C language series)
猜你喜欢
Processing polyhedron change
5月产品升级观察站
System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
【Spark】. Explanation of several icons of scala file in idea
Mode pont
Vivado error code [drc pdcn-2721] resolution
组合模式(Composite )
awk工具
To solve the difficulties of small and medium-sized enterprises, Baidu AI Cloud makes an example
Beifu cx5130 card replacement and transfer of existing authorization files
随机推荐
Processing polyhedron change
MySQL explanation (I)
Dark horse notes - Common APIs
LeetCode_ Stack_ Medium_ 150. evaluation of inverse Polish expression
sed编辑器
外观模式(Facade)
First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology
Learn how to develop owl components by hand (7): practical use of owl projects
What are the common categories of software testing?
code force Party Lemonade
I have a good word to say, and I admire myself
Learning Processing Zoog
Do you know the limitations of automated testing?
Processsing mouse interactive learning
Solutions to insufficient display permissions of find and Du -sh
H - Sumsets POJ 2229
适配器模式(Adapter)
MySQL数据库讲解(三)
P2393 yyy loves Maths II
Beifu PLC realizes data power-off maintenance based on cx5130