Advertisement
fruffl

Array vs Stack vs Queue

Apr 25th, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1.  
  2.     // array
  3.     $array = (new DataTypeArray())->push('The')->push('quick')->push('brown')->push('fox');
  4.     foreach($array as $word) print $word." "; // The quick brown fox
  5.    
  6.     print $array->pop()."\n"; // fox
  7.     print $array->pop()."\n"; // brown
  8.     print $array->pop()."\n"; // quick
  9.     print $array->pop()."\n"; // The
  10.  
  11.  
  12.     // stack
  13.     $stack = (new Stack())->push('The')->push('quick')->push('brown')->push('fox');
  14.     foreach($stack as $word) print $word." "; // fox brown quick The
  15.    
  16.     print $stack->pop()."\n"; // fox
  17.     print $stack->pop()."\n"; // brown
  18.     print $stack->pop()."\n"; // quick
  19.     print $stack->pop()."\n"; // The
  20.  
  21.     // queue
  22.     $queue = (new Queue())->push('The')->push('quick')->push('brown')->push('fox');
  23.     foreach($queue as $word) print $word." "; // The quick brown fox
  24.         print "\n";
  25.    
  26.     print $queue->pop()."\n"; // The
  27.     print $queue->pop()."\n"; // quick
  28.     print $queue->pop()."\n"; // brown
  29.     print $queue->pop()."\n"; // fox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement