daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Jul 23rd, 2012 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class element{
  3.     var $val;
  4.     var $next;
  5. }
  6.  
  7. class stack{
  8.     var $current = null;
  9.    
  10.     function push($val){
  11.         $element = new element();
  12.         $element->val = $val;
  13.         $element->next = $this->current;
  14.         $this->current = $element;
  15.     }
  16.    
  17.     function pop(){
  18.         if($this->current == null) return -1;
  19.         $tmp = $this->current;
  20.         $this->current = $tmp->next;
  21.         return $tmp->val . "\n";
  22.     }
  23. }
  24.  
  25. $stack = new stack();
  26.  
  27. $stack->push(5);
  28. $stack->push(4);
  29. $stack->push(2);
  30.  
  31. echo $stack->pop();
  32. echo $stack->pop();
  33. echo $stack->pop();
  34. echo $stack->pop();
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top