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

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.

主站蜘蛛池模板: 台北县| 兖州市| 铜鼓县| 嘉禾县| 勃利县| 蒲城县| 青河县| 太湖县| 马山县| 达拉特旗| 秦皇岛市| 顺平县| 延川县| 荥阳市| 浙江省| 和田市| 滕州市| 达日县| 苏尼特左旗| 牡丹江市| 西乌珠穆沁旗| 搜索| 祁东县| 都兰县| 双城市| 青铜峡市| 盈江县| 大港区| 庆城县| 西藏| 南乐县| 兰考县| 那坡县| 鄂州市| 阿克苏市| 房产| 汾西县| 山丹县| 澎湖县| 固镇县| 浑源县|