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();
javascript 链式栈
最新推荐文章于 2022-11-26 17:37:36 发布