<?php
/*
Queue class
Version 1.0
by Johan De Klerk
Description:
Class for implementing a queue data structure
queues are first in first out
Log:
2003/09/26: class created
2003/09/30: by Johan De Klerk:
currentKey() function added
replaceElement($element) function added
removeElement() function added
*/
class Queue {
var $q_array = array();
function push($object) {
array_push($this->q_array,$object);
}
function pop() {
if ($this->size() != 0) {
return array_shift($this->q_array);
}
else {
return false;
}
}
function element($no) {
return $this->q_array[$no];
}
function firstElement() {
return reset($this->q_array);
}
function nextElement() {
return next($this->q_array);
}
function prevElement() {
return prev($this->q_array);
}
function replaceElement($element) {
$key = $this->currentKey();
$this->q_array[$key] = $element;
}
function removeElement() {
$key = $this->currentKey();
unset($this->q_array[$key]);
}
function currentElement() {
return current($this->q_array);
}
function currentKey() {
return key($this->q_array);
}
function size() {
return sizeof($this->q_array);
}
}
?>