blob: 795c433bd1d8a76f84f9ce82dd14b74b0ec762eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/*
* Item
*
*/
function Item() {
var obj;
var nxt;
}
/*
* Queue
*
*/
function Queue() {
var topItem;
var botItem;
}
Queue.prototype.empty = function() {
return this.topItem == null;
}
Queue.prototype.push = function(p) {
var b = new Item();
if (this.empty()) {
this.topItem = b;
} else {
this.botItem.next = b;
}
this.botItem = b;
this.botItem.obj = p;
}
Queue.prototype.pop = function() {
if (this.empty()) {
throw('Queue empty');
}
var b = this.topItem;
this.topItem = b.nxt;
return b.obj;
}
|