public function testIsEmpty() { // Remove the following lines when you implement this test. $this->assertFalse($this->object->isEmpty()); $this->object->clear(); $this->assertFalse(!$this->object->isEmpty()); }
/** * @link http://php.net/manual/en/iterator.rewind.php * @return void */ function rewind() { $this->stack = new LinkedStack(); $this->pushLeft($this->root); if (!$this->stack->isEmpty()) { $this->node = $this->stack->last(); $this->key = 0; } }
/** * @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++; }
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(); } }
/** * Vložení souboru * * @param string * @param string * @return void */ protected function callInclude(array $include) { $value = $this->reduceValue($include[2]); if ($value[0] !== 'string') { throw new CompileException("Název vkládaného souboru musí být řetězec"); } $file = Compiler::stringDecode($value[1]); $path = ($this->files->isEmpty() ? '' : dirname($this->files->top()) . DIRECTORY_SEPARATOR) . $file; $extension = pathinfo($file, PATHINFO_EXTENSION); if (!is_file($path) || !is_readable($path)) { throw new CompileException("Soubor '{$path}' neexistuje nebo jej nelze přečíst"); } elseif ($extension == 'iss') { $this->addFile($path); try { $tree = $this->parser->parse(file_get_contents($this->getFile())); if ($include[3] !== NULL) { $block = new Media($include[3], $include[4]); $block->properties = $tree->properties; $this->reduceBlock($block); } else { $this->reduceBlock($tree); } } catch (CompileException $e) { throw $e->setFile($this->getFile()); } $this->removeFile($path); return; } elseif ($extension == 'css') { $this->addFile($path); $context =& $this->getReducedContext(); $context[] = file_get_contents($path); $this->removeFile($path); return; } throw new CompileException("Soubor '{$path}' nemá koncovku .css ani .iss"); }
class Stack { private $data = array(); public function push($element) { $this->data[] = $element; } public function pop() { if ($this->isEmpty()) { return null; } return array_pop($this->data); } public function isEmpty() { return count($this->data) == 0; } } foreach (file($argv[1]) as $line) { $stack = new Stack(); foreach (explode(" ", trim($line)) as $number) { $stack->push($number); } $toPrint = array(); while (!$stack->isEmpty()) { $toPrint[] = $stack->pop(); $stack->pop(); } echo implode(" ", $toPrint) . "\n"; }
} else { echo "stack is empty"; } } public function isEmpty() { if ($this->index == -1) { return true; } else { return false; } } public function first() { echo $this->stackArray[$this->index]; } public function last() { echo $this->stackArray[0]; } } $newStack = new Stack(); $newStack->push(2); $newStack->push(6); $newStack->pop(); $newStack->pop(); $newStack->pop(); $newStack->isEmpty(); $newStack->first(); $newStack->last(); $newStack->getElement(1);