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

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.

主站蜘蛛池模板: 青阳县| 峨山| 丰县| 奈曼旗| 安溪县| 大埔区| 曲麻莱县| 庄浪县| 洪江市| 娄底市| 和硕县| 扶绥县| 屏山县| 南皮县| 东安县| 武山县| 金寨县| 宜都市| 丰原市| 南陵县| 彝良县| 岳池县| 禹城市| 永仁县| 泸西县| 彰化市| 嘉义县| 固安县| 隆林| 正定县| 东乡| 秀山| 阿荣旗| 辽宁省| 肇州县| 左权县| 高尔夫| 西峡县| 胶南市| 定陶县| 中山市|