Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,21 @@
class Fifo {
private $data = array();
public function push($element){
array_push($this->data, $element);
}
public function pop(){
if ($this->isEmpty()){
throw new Exception('Attempt to pop from an empty queue');
}
return array_shift($this->data);
}
//Alias functions
public function enqueue($element) { $this->push($element); }
public function dequeue() { return $this->pop(); }
//Note: PHP prevents a method name of 'empty'
public function isEmpty(){
return empty($this->data);
}
}

View file

@ -0,0 +1,9 @@
$foo = new Fifo();
$foo->push('One');
$foo->enqueue('Two');
$foo->push('Three');
echo $foo->pop(); //Prints 'One'
echo $foo->dequeue(); //Prints 'Two'
echo $foo->pop(); //Prints 'Three'
echo $foo->pop(); //Throws an exception