当前位置: 首页>>代码示例>>PHP>>正文


PHP Stack::count方法代码示例

本文整理汇总了PHP中Stack::count方法的典型用法代码示例。如果您正苦于以下问题:PHP Stack::count方法的具体用法?PHP Stack::count怎么用?PHP Stack::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stack的用法示例。


在下文中一共展示了Stack::count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testALL

 public function testALL()
 {
     $this->assertTrue($this->object->count() == 10);
     $this->assertTrue($this->object->pop()->toNative() == 9);
     $this->assertTrue($this->object->count() == 9);
     $this->object->push(1);
     $this->assertTrue($this->object->remove(1));
     $this->object->push(78);
 }
开发者ID:robo47,项目名称:BlazeFramework,代码行数:9,代码来源:StackTest.php

示例2: process

 private function process()
 {
     //echo "Processing postfix notation:\n\n";
     $tempStack = new Stack();
     while ($token = $this->rpnNotation->dequeue()) {
         if ($token instanceof Number) {
             $tempStack->push($token);
         } elseif ($token instanceof Operator || $token instanceof Funct) {
             /** @var $token Operator|Funct */
             if ($tempStack->count() < $token->numOfArgs()) {
                 throw new Exception(sprintf('Required %d arguments, %d given.', $token->numOfArgs(), $tempStack->count()));
             }
             $arg = $tempStack->popMultiple($token->numOfArgs());
             $tempStack->push($token->execute(array_reverse($arg)));
         }
     }
     return $tempStack->pop()->value;
 }
开发者ID:rn0,项目名称:php-calc,代码行数:18,代码来源:onp.php

示例3: evaluateExpression

 /**
  * Vyhodnocení výrazu
  *
  * @param array
  * @return array
  */
 protected function evaluateExpression(array $expr)
 {
     if ($expr[0] != 'expression') {
         return $this->reduceValue($expr);
     }
     array_shift($expr);
     //převod výrazu do postfixové notace
     $postfix = array();
     $stack = new Stack();
     foreach ($expr as $symbol) {
         if ($symbol == '(') {
             $stack->push($symbol);
         } elseif ($symbol == ')') {
             while ($top = $stack->pop()) {
                 if ($top == '(') {
                     break;
                 }
                 $postfix[] = $top;
             }
             $top = $stack->top();
             if ($top[0] == 'unary' && array_key_exists($top[1], Compiler::$unaryOperators)) {
                 $postfix[] = $stack->pop();
             }
         } elseif ($symbol[0] == 'binary' && array_key_exists($symbol[1], Compiler::$binaryOperators)) {
             if ($stack->count() == 0) {
                 $stack->push($symbol);
                 continue;
             }
             $top = $stack->top();
             while ($top != '(' && $stack->count() > 0 && $top[0] == 'binary' && Compiler::$binaryOperators[$symbol[1]] <= Compiler::$binaryOperators[$top[1]]) {
                 $postfix[] = $stack->pop();
                 $top = $stack->top();
             }
             $stack->push($symbol);
         } elseif ($symbol[0] == 'unary' && array_key_exists($symbol[1], Compiler::$unaryOperators)) {
             $stack->push($symbol);
         } else {
             $postfix[] = $this->reduceValue($symbol);
             $top = $stack->top();
             if ($top[0] == 'unary' && array_key_exists($top[1], Compiler::$unaryOperators)) {
                 $postfix[] = $stack->pop();
             }
         }
     }
     while ($stack->count() > 0) {
         $postfix[] = $stack->pop();
     }
     //vyhodnocení výrazu
     $stack->clear();
     foreach ($postfix as $symbol) {
         if ($symbol[0] == 'unary' && array_key_exists($symbol[1], Compiler::$unaryOperators)) {
             if ($stack->count() < 1) {
                 throw new CompileException("Nedostatek operandů pro unární operátor '{$symbol['1']}'");
             }
             $symbol = $this->evaluateUnaryOperation($symbol[1], $stack->pop());
         } elseif ($symbol[0] == 'binary' && array_key_exists($symbol[1], Compiler::$binaryOperators)) {
             if ($stack->count() < 2) {
                 throw new CompileException("Nedostatek operandů pro binární operátor '{$symbol['1']}'");
             }
             $value2 = $stack->pop();
             $symbol = $this->evaluateBinaryOperation($symbol[1], $stack->pop(), $value2);
         }
         $stack->push($symbol);
     }
     if ($stack->count() != 1) {
         throw new CompileException("Výsledkem výrazu má být pouze 1 hodnota");
     }
     return $stack->pop();
 }
开发者ID:enumag,项目名称:ivory,代码行数:75,代码来源:Analyzer.php


注:本文中的Stack::count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。