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

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.

主站蜘蛛池模板: 莫力| 南通市| 克拉玛依市| 霍林郭勒市| 称多县| 白沙| 海原县| 浑源县| 赤城县| 东方市| 灵丘县| 福泉市| 彭州市| 吉水县| 盖州市| 永川市| 白玉县| 富宁县| 闸北区| 读书| 武隆县| 永清县| 渝中区| 元阳县| 苗栗市| 新郑市| 灵丘县| 阳谷县| 拉萨市| 霍城县| 桐庐县| 汉寿县| 青海省| 偏关县| 洮南市| 平潭县| 安陆市| 通江县| 绥阳县| 那曲县| 郧西县|