當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。