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


PHP Stack::push方法代码示例

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


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

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

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

示例3: pushIfNotNull

 private function pushIfNotNull($direction, BinaryTree $n)
 {
     $next = $n->{$direction}();
     if ($next !== null) {
         $this->stack->push($next);
     }
 }
开发者ID:pramoddas,项目名称:Ardent,代码行数:7,代码来源:PreOrderIterator.php

示例4: add

 /**
  * register a class for startup
  * @param string $classname
  * @param bool $useDI
  */
 public static function add($classname, $useDI = false)
 {
     if (is_array(self::$startup) && is_array(self::$DIstartup)) {
         if ($useDI) {
             self::$DIstartup[] = $classname;
         } else {
             self::$startup[] = $classname;
         }
     } else {
         if ($useDI) {
             self::$DIstartup->push($classname);
         } else {
             self::$startup->push($classname);
         }
     }
 }
开发者ID:jankal,项目名称:mvc,代码行数:21,代码来源:Service.php

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

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

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

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

示例9: atFontFace

 /**
  * Definice vlastního písma
  *
  * @return bool
  */
 protected function atFontFace()
 {
     $x = $this->getOffset();
     if (($this->getActualBlock() instanceof Main || $this->getActualBlock() instanceof Media || $this->getActualBlock() instanceof Mixin) && $this->char('@font-face') && $this->char('{')) {
         $block = new FontFace();
         $this->getActualBlock()->properties[] = $block;
         $this->stack->push($block);
         return TRUE;
     }
     $this->setOffset($x);
     return FALSE;
 }
开发者ID:enumag,项目名称:ivory,代码行数:17,代码来源:Parser.php

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

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

示例12: isEmpty

    public $item;
    public $next;
}
class Stack
{
    private $first = null;
    public function isEmpty()
    {
        return $this->first == null;
    }
    public function push($item)
    {
        $oldfirst = $this->first;
        $this->first = new Node();
        $this->first->item = $item;
        $this->first->next = $oldfirst;
    }
    public function pop()
    {
        $item = $this->first->item;
        $this->first = $this->first->next;
        return $item;
    }
}
$list = new Stack();
$list->push(1);
$list->push(2);
$list->push(3);
echo $list->pop();
echo $list->pop();
echo $list->pop();
开发者ID:eltonoliver,项目名称:Algorithms,代码行数:31,代码来源:stack.php

示例13: in2post

 /**
  * Infix to Postfix
  *
  * Converts an infix (standard) equation to postfix (RPN) notation.
  * Sets the internal variable $this->postFix for the Parser::solvePF()
  * function to use.
  *
  * @link http://en.wikipedia.org/wiki/Infix_notation Infix Notation
  * @link http://en.wikipedia.org/wiki/Reverse_Polish_notation Reverse Polish Notation
  * @param String $infix A standard notation equation
  * @throws \Exception When parenthesis are mismatched
  * @return Array Fully formed RPN Stack
  */
 public static function in2post($infix)
 {
     // if an equation was not passed, use the one that was passed in the constructor
     //$infix = (isset($infix)) ? $infix : $this->inFix;
     //check to make sure 'valid' equation
     self::checkInfix($infix);
     $pf = array();
     $ops = new Stack();
     //$vars = new Stack();
     // remove all white-space
     $infix = preg_replace("/\\s/", "", $infix);
     // Create postfix array index
     $pfIndex = 0;
     //what was the last character? (useful for discerning between a sign for negation and subtraction)
     $lChar = '';
     //loop through all the characters and start doing stuff ^^
     for ($i = 0; $i < strlen($infix); $i++) {
         // pull out 1 character from the string
         $chr = substr($infix, $i, 1);
         // if the character is numerical
         if (preg_match('/[0-9.]/i', $chr)) {
             // if the previous character was not a '-' or a number
             if (!preg_match('/[0-9.]/i', $lChar) && $lChar != "" && (isset($pf[$pfIndex]) && $pf[$pfIndex] != "-")) {
                 $pfIndex++;
             }
             // increase the index so as not to overlap anything
             // Add the number character to the array
             if (isset($pf[$pfIndex])) {
                 $pf[$pfIndex] .= $chr;
             } else {
                 $pf[$pfIndex] = $chr;
             }
         } elseif (in_array($chr, self::$SEP['open'])) {
             // if the last character was a number, place an assumed '*' on the stack
             if (preg_match('/[0-9.]/i', $lChar)) {
                 $ops->push('*');
             }
             $ops->push($chr);
         } elseif (in_array($chr, self::$SEP['close'])) {
             // find what set it was i.e. matches ')' with '(' or ']' with '['
             $key = array_search($chr, self::$SEP['close']);
             // while the operator on the stack isn't the matching pair...pop it off
             while ($ops->peek() != self::$SEP['open'][$key]) {
                 $nchr = $ops->pop();
                 if ($nchr) {
                     $pf[++$pfIndex] = $nchr;
                 } else {
                     throw new \Exception("Error while searching for '" . self::$SEP['open'][$key] . "' in " . self::$inFix, Math::E_NO_SET);
                 }
             }
             $ops->pop();
         } elseif (in_array($chr, self::$ST)) {
             while (in_array($ops->peek(), self::$ST)) {
                 $pf[++$pfIndex] = $ops->pop();
             }
             $ops->push($chr);
             $pfIndex++;
         } elseif (in_array($chr, self::$ST1)) {
             while (in_array($ops->peek(), self::$ST1) || in_array($ops->peek(), self::$ST)) {
                 $pf[++$pfIndex] = $ops->pop();
             }
             $ops->push($chr);
             $pfIndex++;
         } elseif (in_array($chr, self::$ST2)) {
             // if it is a '-' and the character before it was an operator or nothingness (e.g. it negates a number)
             if ((in_array($lChar, array_merge(self::$ST1, self::$ST2, self::$ST, self::$SEP['open'])) || $lChar == "") && $chr == "-") {
                 // increase the index because there is no reason that it shouldn't..
                 $pfIndex++;
                 $pf[$pfIndex] = $chr;
             } else {
                 while (in_array($ops->peek(), array_merge(self::$ST1, self::$ST2, self::$ST))) {
                     $pf[++$pfIndex] = $ops->pop();
                 }
                 $ops->push($chr);
                 $pfIndex++;
             }
         }
         // make sure we record this character to be referred to by the next one
         $lChar = $chr;
     }
     // if there is anything on the stack after we are done...add it to the back of the RPN array
     while (($tmp = $ops->pop()) !== false) {
         $pf[++$pfIndex] = $tmp;
     }
     // re-index the array at 0
     $pf = array_values($pf);
     // set the private variable for later use if needed
//.........这里部分代码省略.........
开发者ID:geekman-rohit,项目名称:eos,代码行数:101,代码来源:Parser.php

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

示例15: calculate_polish_notation

function calculate_polish_notation($notation)
{
    $calc_stack = new Stack();
    for ($i = 0; $i < strlen($notation); $i++) {
        $current_number = '';
        if ($notation[$i] == '.') {
            ++$i;
            do {
                $current_number .= $notation[$i];
            } while (is_numeric($notation[++$i]));
            --$i;
            $calc_stack->push($current_number);
            $current_number = '';
        }
        if ($notation[$i] == '-' or $notation[$i] == '+' or $notation[$i] == '*' or $notation[$i] == '/' or $notation[$i] == '^') {
            $a = $calc_stack->pop();
            $b = $calc_stack->pop();
            if ($notation[$i] == '-') {
                $result = $b - $a;
            } elseif ($notation[$i] == '+') {
                $result = $a + $b;
            } elseif ($notation[$i] == '*') {
                $result = $a * $b;
            } elseif ($notation[$i] == '/') {
                if ($a == 0) {
                    show_error('В выражении возникло деление на ноль.');
                    return;
                } else {
                    $result = $b / $a;
                }
            } elseif ($notation[$i] == '^') {
                $result = pow($b, $a);
            }
            $calc_stack->push($result);
        }
    }
    return $result;
}
开发者ID:Aisorfe,项目名称:line_calculator,代码行数:38,代码来源:index.php


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