javascript 链式栈

来源:互联网 发布:淘宝客户端for mac 编辑:程序博客网 时间:2024/05/29 07:16
function Stack() {this.top = null;this.size = 0;}Stack.prototype = {constructor: Stack,push: function(data) {if (data == null) {return false;} else {var Node = {data: data,next: null};Node.next = this.top;this.top = Node;this.size++;}},pop: function() {if (this.size == 0) {return null;} else {var data = this.top.data;this.top = this.top.next;this.size--;return data;}}};var Stack = new Stack();Stack.push(1);Stack.push(2);Stack.pop();

0 0
原创粉丝点击