官术网_书友最值得收藏!

Testing the queue

To test this queue, you can simply instantiate it and add/remove some items to/from the queue:

var simpleQueue = new Queue();
simpleQueue.add(10);
simpleQueue.add(20);

console.log(simpleQueue.items); // prints undefined

console.log(simpleQueue.size()); // prints 2

console.log(simpleQueue.remove()); // prints 10

console.log(simpleQueue.size()); // prints 1

simpleQueue.clear();

console.log(simpleQueue.size()); // prints 0

As you can note from the preceding code, all elements are treated the same. Irrespective of the data that they contain, elements are always treated in a FIFO fashion. Although that is a good approach, sometimes we may need something more: the ability to prioritize elements that are coming in and leaving the queue, as we can note in the next section.

主站蜘蛛池模板: 镇平县| 客服| 镇安县| 浏阳市| 凭祥市| 宁远县| 绥芬河市| 宿松县| 唐山市| 清远市| 慈溪市| 札达县| 阳新县| 永昌县| 安溪县| 高清| 武陟县| 武威市| 海宁市| 马尔康县| 澜沧| 来凤县| 民乐县| 响水县| 永州市| 临桂县| 玉田县| 香港 | 共和县| 湖南省| 吉木乃县| 西峡县| 宜黄县| 营山县| 类乌齐县| 永平县| 佛教| 高密市| 古蔺县| 永吉县| 宣武区|