Add new clothing system
[18plus-7leafadventure.git] / src / Queue.as
blobba3068e9c9d349382568af993bb3a2d29538aa83
1 package
3 /**
4 * A queue that works by the FIFO (first in, first out) principle.
5 * It can store any type of data and has no fixed size.
6 * @author Tox, webcodesign.de
7 */
8 public class Queue
10 private var q:Array = [];
11 public var l:int = 0;
13 /**
14 * CTOR
16 public function Queue() { }
19 public function dump():void {
20 for (var i:int = 0; i < q.length; i++) {
21 trace("[" + i + "]=",q[i]);
25 /**
26 * Writes data to the end of the queue.
27 * @param d Data to write, can be of any type.
29 public function write(d:*):void {q.push(d);}
31 /**
32 * Reads data from the beginning of the queue.
33 * @return Data stored at the beginning of the queue.
35 public function read():* { l--; return (empty) ? null : q.shift(); }
37 /**
38 * Checks if the queue is empty and returns the result.
40 public function get empty():Boolean { return (q.length <= 0); }
42 /**
43 * Returns the data of the first queue element without removing it.
44 * @return Data of the first queue element.
46 public function spy():* {return (empty) ? null : q[0];}