通过php数组构造简单的顺序栈

废话少说,上代码(talk is easy ,show me the code):

   size = $size;
		}
	
		//获取栈顶元素
		public function pop(){
			if(count($this->stack) === 0){
				return false;
			}
			return array_pop($this->stack);
		}
	
		//向栈中推入元素
		public function push($value){
			if(count($this->stack) === $this->size){
				return false;
			}
	
			array_push($this->stack, $value);
			return true;
		}
	
		//返回栈的大小
		public function size(){
			return count($this->stack);
		}
	
		//判断栈是否时空栈
		public function isEmpty(){
			return current($this->stack)===false;
		}
	}
	
	
	
	$newStack = new SimpleStack(15);
	var_dump($newStack->isEmpty());
	
	$newStack->push(111);
	$newStack->push("lirui");
	$newStack->push("33333");
	$newStack->pop();
	
	var_dump($newStack->size());

你可能感兴趣的:(通过php数组构造简单的顺序栈)