- 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.
推薦閱讀
- 現代C++編程:從入門到實踐
- Mastering Selenium WebDriver
- AngularJS深度剖析與最佳實踐
- Hands-On C++ Game Animation Programming
- C++程序設計基礎教程
- Python時間序列預測
- Unity UI Cookbook
- 零基礎趣學C語言
- Python入門很輕松(微課超值版)
- 零基礎輕松學C++:青少年趣味編程(全彩版)
- IPython Interactive Computing and Visualization Cookbook
- Visual Basic 程序設計實踐教程
- 量子計算機編程:從入門到實踐
- JavaWeb從入門到精通(視頻實戰版)
- 利用Python駕馭Stable Diffusion:原理解析、擴展開發與高級應用(智能系統與技術叢書)