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


PHP Stack::pop方法代码示例

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


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

示例1: stack

 /**
  * @param array[array|string|int] $args
  * @return void
  */
 public function stack(array $args)
 {
     $stack = new \Stack();
     $stack->push("test");
     $stack->push("test2");
     var_dump($stack->getArray());
     $this->response->outLine($stack->pop());
     $this->response->outLine($stack->pop());
 }
开发者ID:jankal,项目名称:mvc,代码行数:13,代码来源:TestController.php

示例2: next

 /**
  * @link http://php.net/manual/en/iterator.next.php
  * @return void
  */
 function next()
 {
     /**
      * @var BinaryTree $node
      */
     $node = $this->stack->pop();
     $this->pushIfNotNull('right', $node);
     $this->pushIfNotNull('left', $node);
     if ($this->stack->isEmpty()) {
         $this->value = $this->key = null;
         return;
     }
     $this->value = $this->stack->last();
     $this->key++;
 }
开发者ID:pramoddas,项目名称:Ardent,代码行数:19,代码来源:PreOrderIterator.php

示例3: testStructure

 public static function testStructure()
 {
     $stack = new Stack();
     if ($stack->getCount() !== 0) {
         self::printError("problem creating a new stack - count not 0");
     }
     // test push
     $stack->push('push1');
     $stack->push('push2');
     $stack->push('push3');
     $stack->push('push4');
     $stack->push('push5');
     $stack->push('push6');
     if ($stack->getCount() !== 6) {
         self::printError("problem pushing to stack - count not 6");
     }
     // test pop
     $data1 = $stack->pop();
     if ($data1 !== 'push6') {
         self::printError("problem popping from stack - wrong item found");
     }
     if ($stack->getCount() !== 5) {
         self::printError("problem popping from stack - count not 5");
     }
     // display... for now
     $stack->display();
 }
开发者ID:phlare,项目名称:utils,代码行数:27,代码来源:TestStack.php

示例4: blockEnd

 /**
  * Konec bloku
  *
  * @return bool
  */
 protected function blockEnd()
 {
     if (!$this->getActualBlock() instanceof Main && $this->char('}')) {
         $this->stack->pop();
         return TRUE;
     }
     return FALSE;
 }
开发者ID:enumag,项目名称:ivory,代码行数:13,代码来源:Parser.php

示例5: testInsertAndRemove

 public function testInsertAndRemove()
 {
     $Stack = new Stack();
     $Stack->push('Radig');
     $this->assertIdentical($Stack->size(), 1);
     $this->assertIdentical($Stack->nth(), 'Radig');
     $Stack->push('CakePHP');
     $this->assertIdentical($Stack->size(), 2);
     // testa com 1-lookahead
     $this->assertIdentical($Stack->nth(), 'CakePHP');
     // teste com 2-lookahead
     $this->assertIdentical($Stack->nth(2), 'Radig');
     $this->assertIdentical($Stack->pop(), 'CakePHP');
     $this->assertIdentical($Stack->pop(), 'Radig');
     $this->assertIdentical($Stack->pop(), null);
     unset($Stack);
 }
开发者ID:schnauss,项目名称:rutils,代码行数:17,代码来源:stack.test.php

示例6: postfixArray

 public static function postfixArray($s)
 {
     $stack = new Stack();
     for ($i = 0; $i < count($s); $i++) {
         $item = $s[$i];
         if ($item->type == "Integer" || $item->type == "Variable") {
             $stack->push($item);
         } else {
             $tree = new Tree();
             $tree->operator = $item;
             $tree->right = $stack->pop();
             $tree->left = $stack->pop();
             $stack->push($tree);
         }
     }
     return $stack->pop();
 }
开发者ID:no92,项目名称:valide,代码行数:17,代码来源:Tree.php

示例7: tokenize

 /** 
  * Tokenize a soap type
  *
  * @param string $type  Type
  *
  * @return array         Tokens
  */
 public static function tokenize($type)
 {
     $stack = new Stack();
     $stack->push(SOAP_STATE_DEFAULT);
     $stack->push(SOAP_STATE_TYPE);
     $tokens = array();
     $token = '';
     $len = strlen($type);
     // We don't actually care whether we're inside of a type or not
     // That's why there aren't separate states for inside and outside of braces
     for ($pos = 0; $pos < $len; ++$pos) {
         $char = $type[$pos];
         $nextChar = isset($type[$pos + 1]) ? $type[$pos + 1] : null;
         switch ($stack->top()) {
             case SOAP_STATE_DEFAULT:
                 if (ctype_alnum($nextChar)) {
                     $stack->push(SOAP_STATE_TYPE);
                 } elseif (in_array($char, self::$whitespace)) {
                     $tokens[] = array('code' => SOAP_WHITESPACE, 'token' => $char);
                 } elseif ($char === '{') {
                     $tokens[] = array('code' => SOAP_OPEN_BRACE, 'token' => $char);
                 } elseif ($char === '}') {
                     $tokens[] = array('code' => SOAP_CLOSE_BRACE, 'token' => $char);
                 } elseif ($char === ';') {
                     $tokens[] = array('code' => SOAP_SEMICOLON, 'token' => $char);
                 }
                 break;
             case SOAP_STATE_TYPE:
                 if (ctype_alnum($char)) {
                     $token .= $char;
                     if ($nextChar === ' ') {
                         if (in_array($token, self::$nativeTypes)) {
                             $tokens[] = array('code' => SOAP_NATIVE_TYPE, 'token' => $token);
                         } else {
                             $tokens[] = array('code' => SOAP_USER_TYPE, 'token' => $token);
                         }
                         $token = '';
                         $stack->pop();
                         $stack->push(SOAP_STATE_PROPERTY);
                     }
                 }
                 break;
             case SOAP_STATE_PROPERTY:
                 if (ctype_alnum($char)) {
                     $token .= $char;
                     if ($nextChar === ';' || $nextChar === ' ' || $nextChar === null) {
                         $tokens[] = array('code' => SOAP_PROPERTY, 'token' => $token);
                         $token = '';
                         $stack->pop();
                     }
                 } elseif ($char === ' ') {
                     $tokens[] = array('code' => SOAP_WHITESPACE, 'token' => $char);
                 }
                 break;
         }
     }
     return $tokens;
 }
开发者ID:premreva1987,项目名称:eloqua-php-sdk,代码行数:65,代码来源:SoapTypeTokenizer.php

示例8: 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

示例9: next

 /**
  * @link http://php.net/manual/en/iterator.next.php
  * @return void
  */
 function next()
 {
     /**
      * @var BinaryTree $node
      */
     $node = $this->stack->pop();
     $right = $node->right();
     if ($right !== null) {
         // left-most branch of the right side
         $this->pushLeft($right);
     }
     if ($this->stack->isEmpty()) {
         $this->node = null;
         return;
     }
     $this->node = $this->stack->last();
     $this->key++;
 }
开发者ID:RadekDvorak,项目名称:Ardent,代码行数:22,代码来源:InOrderIterator.php

示例10: next_right

 private function next_right()
 {
     $right = $this->value->right();
     if ($right !== null && !$this->stack->isEmpty() && $right === $this->stack->last()) {
         $this->stack->pop();
         $this->next_push($right);
     } else {
         $this->next_set();
     }
 }
开发者ID:pramoddas,项目名称:Ardent,代码行数:10,代码来源:PostOrderIterator.php

示例11: testStack

 public function testStack()
 {
     $stack = new Stack();
     $this->assertEquals(0, $stack->length());
     $stack->push('foo');
     $this->assertEquals('foo', $stack->peek());
     $this->assertEquals(1, $stack->length());
     $this->assertEquals('foo', $stack->pop());
     $this->assertEquals(0, $stack->length());
 }
开发者ID:raisanen,项目名称:tlon,代码行数:10,代码来源:StackTest.php

示例12: expression

 public function expression($str)
 {
     $input = new Stack();
     $output = new Stack();
     foreach ($this->tokenizer->tokenize($str) as $token) {
         $part = Dictionary::fromString($token);
         $part->isOperator() ? $input->push($part) : $output->push($part);
     }
     while ($operator = $input->pop()) {
         $output->push($operator);
     }
     // Ran out of time, this'll only work with addition
     $op = $output->pop();
     $val = $op->operate($output);
     return $val;
 }
开发者ID:aaronmu,项目名称:calculator,代码行数:16,代码来源:Math.php

示例13: __toString

    public function __toString()
    {
        if ($this->isEmpty()) {
            $itemsString = 'Stack is empty.';
        } else {
            $itemsString = implode(', ', $this->items);
        }
        $itemsString .= PHP_EOL;
        return $itemsString;
    }
}
$stack = new Stack();
$stack->push('A');
echo (string) $stack;
// A
$stack->pop();
echo (string) $stack;
// Stack is empty.
$stack->pop();
echo (string) $stack;
// Stack is empty.
$stack->push('B');
echo (string) $stack;
// B
$stack->push('C');
echo (string) $stack;
// B, C
$stack->push('D');
echo (string) $stack;
// B, C, D
$stack->pop();
开发者ID:paljinov,项目名称:php-data-structures,代码行数:31,代码来源:Stack.php

示例14: pfx

 /**
  * Evaluate postfix notation
  *
  * @param array $tokens
  * @param array $vars
  *
  * @return mixed boolean *false* in failures and *numeric* value in success
  */
 protected function pfx($tokens, $vars = array())
 {
     bcscale($this->precision);
     if ($tokens === false) {
         return false;
     }
     $stack = new Stack();
     foreach ($tokens as $token) {
         // if the token is a binary operator, pop two values off the stack, do the operation, and push the result back on
         if (in_array($token, array('+', '-', '*', '/', '^'))) {
             if (is_null($op2 = $stack->pop()) || is_null($op1 = $stack->pop())) {
                 return $this->error("Internal error");
             }
             switch ($token) {
                 case '+':
                     $stack->push(bcadd($op1, $op2));
                     break;
                 case '-':
                     $stack->push(bcsub($op1, $op2));
                     break;
                 case '*':
                     $stack->push(bcmul($op1, $op2));
                     break;
                 case '/':
                     if ($op2 == 0) {
                         return $this->error("Division by zero");
                     }
                     $stack->push(bcdiv($op1, $op2));
                     break;
                 case '^':
                     $stack->push(bcpow($op1, $op2));
                     break;
             }
             // if the token is a unary operator, pop one value off the stack, do the operation, and push it back on
         } elseif ($token == "_") {
             // if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on
             $stack->push(-1 * $stack->pop());
         } elseif (preg_match("/^([a-z]\\w*)\\(\$/", $token, $matches)) {
             // it's a function!
             $fnn = $matches[1];
             // built-in function:
             if (in_array($fnn, $this->fb)) {
                 if (is_null($op1 = $stack->pop())) {
                     return $this->error("Internal error");
                 }
                 // for the 'arc' trig synonyms
                 $fnn = preg_replace("/^arc/", "a", $fnn);
                 if ($fnn == 'ln') {
                     $fnn = 'log';
                 }
                 if ($fnn == 'sqrt') {
                     $fnn = 'bcsqrt';
                 }
                 $val = $this->strictPrecision(call_user_func($fnn, $op1));
                 $stack->push($val);
             } elseif (array_key_exists($fnn, $this->f)) {
                 // get args
                 $args = array();
                 for ($i = count($this->f[$fnn]['args']) - 1; $i >= 0; $i--) {
                     if (is_null($args[$this->f[$fnn]['args'][$i]] = $stack->pop())) {
                         return $this->error("Internal error");
                     }
                 }
                 $stack->push($this->pfx($this->f[$fnn]['func'], $args));
                 // yay... recursion!!!!
             }
         } else {
             if (is_numeric($token)) {
                 $stack->push($this->strictPrecision($token));
             } elseif (array_key_exists($token, $this->v)) {
                 $stack->push($this->strictPrecision($this->v[$token]));
             } elseif (array_key_exists($token, $vars)) {
                 $stack->push($this->strictPrecision($vars[$token]));
             } else {
                 return $this->error("Undefined variable '{$token}'");
             }
         }
     }
     // when we're out of tokens, the stack should have a single element, the final result
     if ($stack->size() != 1) {
         return $this->error("Internal error");
     }
     return $stack->pop();
 }
开发者ID:schnauss,项目名称:rutils,代码行数:92,代码来源:eval_math.php

示例15: getElement

    function First()
    {
        return $this->stackArray[$this->index];
    }
    function Last()
    {
        return $this->stackArray[0];
    }
    public function getElement($position)
    {
        if ($position <= $this->index + 1) {
            $arrayPosition = $this->index + 1 - $position;
            return $this->stackArray[$arrayPosition];
        } else {
            echo "Invalid";
        }
    }
}
$myStack = new Stack(array(4, 5, 6, 7));
echo $myStack->pop() . "<br>";
echo $myStack->pop() . "<br>";
echo $myStack->pop() . "<br>";
echo $myStack->pop() . "<br>";
//$myStack->push(1);
//$myStack->push(4);
//$myStack->push(5);
//echo "First pop is ", $myStack->pop(),"<br>";
//echo "Second pop is ", $myStack->pop(),"<br>";
//echo "First value of stack is ",$myStack->First(),"<br>";
//$myStack->pop();
//echo "present index value is ",$myStack->getElement(2);
开发者ID:majumder5niru,项目名称:Learning_PHP,代码行数:31,代码来源:stack_with_constructor.php


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