note 114167 deleted from class.splstack by cmb

From: Date: Fri, 10 Sep 2021 12:29:10 +0000
Subject: note 114167 deleted from class.splstack by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216941@lists.php.net to get a copy of this message
Note Submitter: lsroudi at gmail dot com ---- <?php /** * Description of Stack * * (c) lsroudi <http://lsroudi.com/> <lsroudi@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ class Stack { private $splstack; function __construct(\SplStack $splstack) { $this->splstack = $splstack; } public function calculateSomme() { if ($this->splstack->count() > 1){ $val1 = $this->splstack->pop(); $val2 = $this->splstack->pop(); $val = $val1 + $val2; $this->splstack->push($val); $this->calculateSomme(); } } /** * * @return integer */ public function displaySomme() { $result = $this->splstack->pop(); return $result; } } $splstack = new \SplStack(); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $splstack->push(10); $stack = new Stack($splstack); $stack->calculateSomme(); die(var_dump($stack->displaySomme())); // 150 ?> source : https://github.com/lsroudi/OOPWithSPL/blob/master/Stack/Stack.php

« previous php.notes (#216941) next »