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

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.

主站蜘蛛池模板: 泰和县| 长武县| 贡觉县| 玉屏| 自治县| 墨玉县| 昌平区| 荆门市| 宿松县| 漳平市| 青海省| 镇江市| 娄底市| 盐亭县| 卓尼县| 县级市| 赤峰市| 湄潭县| 乾安县| 西贡区| 河南省| 缙云县| 沙雅县| 故城县| 远安县| 军事| 都昌县| 宜良县| 清流县| 舒兰市| 启东市| 临朐县| 洪江市| 东安县| 大关县| 印江| 桂林市| 安康市| 宁阳县| 新昌县| 建昌县|