- Hands-On Data Structures and Algorithms with JavaScript
- Kashyap Mukkamala
- 110字
- 2021-06-30 19:12:12
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.
推薦閱讀
- JavaScript從入門到精通(微視頻精編版)
- Vue.js 2 and Bootstrap 4 Web Development
- 單片機應用技術(shù)
- RabbitMQ Cookbook
- Python深度學習:基于TensorFlow
- Visual C#.NET Web應用程序設計
- 編寫高質(zhì)量代碼:改善Objective-C程序的61個建議
- 移動增值應用開發(fā)技術(shù)導論
- ActionScript 3.0從入門到精通(視頻實戰(zhàn)版)
- Learning Nessus for Penetration Testing
- Web Developer's Reference Guide
- 官方 Scratch 3.0 編程趣味卡:讓孩子們愛上編程(全彩)
- 程序員必會的40種算法
- AutoCAD基礎教程
- Android熱門應用開發(fā)詳解