Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class element{
- var $val;
- var $next;
- }
- class stack{
- var $current = null;
- function push($val){
- $element = new element();
- $element->val = $val;
- $element->next = $this->current;
- $this->current = $element;
- }
- function pop(){
- if($this->current == null) return -1;
- $tmp = $this->current;
- $this->current = $tmp->next;
- return $tmp->val . "\n";
- }
- }
- $stack = new stack();
- $stack->push(5);
- $stack->push(4);
- $stack->push(2);
- echo $stack->pop();
- echo $stack->pop();
- echo $stack->pop();
- echo $stack->pop();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement