- 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.
推薦閱讀
- Java逍遙游記
- Building a RESTful Web Service with Spring
- C和C++安全編碼(原書第2版)
- C語言程序設(shè)計(jì)
- 用Flutter極速構(gòu)建原生應(yīng)用
- Unity 5.x By Example
- Linux命令行與shell腳本編程大全(第4版)
- Regression Analysis with Python
- JavaScript+jQuery網(wǎng)頁特效設(shè)計(jì)任務(wù)驅(qū)動(dòng)教程
- 零基礎(chǔ)學(xué)HTML+CSS
- Implementing Domain:Specific Languages with Xtext and Xtend
- 深入理解MySQL主從原理
- Mastering Swift 4(Fourth Edition)
- Building an E-Commerce Application with MEAN
- JavaWeb入門經(jīng)典