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

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.

主站蜘蛛池模板: 饶阳县| 南川市| 泗洪县| 繁峙县| 三原县| 边坝县| 蕲春县| 奈曼旗| 大竹县| 玉门市| 湘潭市| 怀柔区| 铁岭县| 康定县| 文水县| 德兴市| 茶陵县| 祁连县| 遂昌县| 鹤壁市| 射洪县| 仪征市| 通海县| 巩留县| 芦山县| 思茅市| 景谷| 桐乡市| 牡丹江市| 鱼台县| 定西市| 修文县| 河池市| 潍坊市| 萝北县| 台安县| 盖州市| 油尖旺区| 太保市| 建阳市| 巴里|