Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/queue
Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/queue
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras |
Filename: | Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/queue |
Read OK: | ✔ |
File size: | 0213 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* queue class GCW 23/01/95 */ class queue { front, rear; add(x); // add an item to the rear /* get() returns nil from an empty queue */ get(); // remove an item from the front } queue::queue() { front = rear = nil; return this; } queue::add(x) { if (typeof(rear)) rear = (rear[1] = vector { x; nil; }); else front = rear = vector { x; nil; }; } queue::get() { local item; if (!typeof(front)) return nil; item = front[0]; if (!typeof(front = front[1])) rear = nil; return item; }
00000000 2f 2a 20 71 75 65 75 65 20 63 6c 61 73 73 20 20 |/* queue class | 00000010 20 20 20 20 20 20 47 43 57 20 20 32 33 2f 30 31 | GCW 23/01| 00000020 2f 39 35 20 20 2a 2f 20 0a 0a 63 6c 61 73 73 20 |/95 */ ..class | 00000030 71 75 65 75 65 0a 7b 0a 20 66 72 6f 6e 74 2c 20 |queue.{. front, | 00000040 72 65 61 72 3b 0a 20 61 64 64 28 78 29 3b 20 20 |rear;. add(x); | 00000050 20 20 20 20 20 20 2f 2f 20 61 64 64 20 61 6e 20 | // add an | 00000060 69 74 65 6d 20 74 6f 20 74 68 65 20 72 65 61 72 |item to the rear| 00000070 0a 20 2f 2a 20 67 65 74 28 29 20 72 65 74 75 72 |. /* get() retur| 00000080 6e 73 20 6e 69 6c 20 66 72 6f 6d 20 61 6e 20 65 |ns nil from an e| 00000090 6d 70 74 79 20 71 75 65 75 65 20 20 2a 2f 0a 20 |mpty queue */. | 000000a0 67 65 74 28 29 3b 20 20 20 20 20 20 20 20 20 2f |get(); /| 000000b0 2f 20 72 65 6d 6f 76 65 20 61 6e 20 69 74 65 6d |/ remove an item| 000000c0 20 66 72 6f 6d 20 74 68 65 20 66 72 6f 6e 74 0a | from the front.| 000000d0 7d 0a 0a 71 75 65 75 65 3a 3a 71 75 65 75 65 28 |}..queue::queue(| 000000e0 29 0a 7b 0a 20 66 72 6f 6e 74 20 3d 20 72 65 61 |).{. front = rea| 000000f0 72 20 3d 20 6e 69 6c 3b 0a 20 72 65 74 75 72 6e |r = nil;. return| 00000100 20 74 68 69 73 3b 0a 7d 0a 0a 71 75 65 75 65 3a | this;.}..queue:| 00000110 3a 61 64 64 28 78 29 0a 7b 0a 20 69 66 20 28 74 |:add(x).{. if (t| 00000120 79 70 65 6f 66 28 72 65 61 72 29 29 0a 20 20 20 |ypeof(rear)). | 00000130 72 65 61 72 20 3d 20 28 72 65 61 72 5b 31 5d 20 |rear = (rear[1] | 00000140 3d 20 76 65 63 74 6f 72 20 7b 20 78 3b 20 6e 69 |= vector { x; ni| 00000150 6c 3b 20 7d 29 3b 0a 20 65 6c 73 65 0a 20 20 20 |l; });. else. | 00000160 66 72 6f 6e 74 20 3d 20 72 65 61 72 20 3d 20 76 |front = rear = v| 00000170 65 63 74 6f 72 20 7b 20 78 3b 20 6e 69 6c 3b 20 |ector { x; nil; | 00000180 7d 3b 0a 7d 0a 0a 71 75 65 75 65 3a 3a 67 65 74 |};.}..queue::get| 00000190 28 29 0a 7b 0a 20 6c 6f 63 61 6c 20 69 74 65 6d |().{. local item| 000001a0 3b 0a 20 69 66 20 28 21 74 79 70 65 6f 66 28 66 |;. if (!typeof(f| 000001b0 72 6f 6e 74 29 29 20 72 65 74 75 72 6e 20 6e 69 |ront)) return ni| 000001c0 6c 3b 0a 20 69 74 65 6d 20 3d 20 66 72 6f 6e 74 |l;. item = front| 000001d0 5b 30 5d 3b 0a 20 69 66 20 28 21 74 79 70 65 6f |[0];. if (!typeo| 000001e0 66 28 66 72 6f 6e 74 20 3d 20 66 72 6f 6e 74 5b |f(front = front[| 000001f0 31 5d 29 29 20 72 65 61 72 20 3d 20 6e 69 6c 3b |1])) rear = nil;| 00000200 0a 20 72 65 74 75 72 6e 20 69 74 65 6d 3b 0a 7d |. return item;.}| 00000210 0a 0a 20 |.. | 00000213