- Hands-On Data Structures and Algorithms with JavaScript
- Kashyap Mukkamala
- 106字
- 2021-06-30 19:12:08
Testing the stack
To test the Stack we have just created, let's instantiate a new stack and call out each of the methods and take a look at how they present us with data:
var stack = new Stack();
stack.push(10);
stack.push(20);
console.log(stack.items); // prints undefined -> cannot be accessed directly
console.log(stack.size()); // prints 2
console.log(stack.peek()); // prints 20
console.log(stack.pop()); // prints 20
console.log(stack.size()); // prints 1
stack.clear();
console.log(stack.size()); // prints 0
When we run the above script we see the logs as specified in the comments above. As expected, the stack provides what appears to be the expected output at each stage of the operations.
推薦閱讀
- Web Scraping with Python
- AngularJS深度剖析與最佳實踐
- Python神經網絡項目實戰
- Visual Basic程序設計實踐教程
- HTML5從入門到精通(第4版)
- OpenCV 4計算機視覺項目實戰(原書第2版)
- Scala for Machine Learning(Second Edition)
- C++反匯編與逆向分析技術揭秘(第2版)
- 創意UI:Photoshop玩轉APP設計
- SQL Server 2016 從入門到實戰(視頻教學版)
- 計算機應用技能實訓教程
- Oracle 12c從入門到精通(視頻教學超值版)
- OpenCV 3.0 Computer Vision with Java
- 原型設計:打造成功產品的實用方法及實踐
- Python3從入門到實戰