summaryrefslogtreecommitdiff
path: root/javascripts/Stack.js
diff options
context:
space:
mode:
Diffstat (limited to 'javascripts/Stack.js')
-rw-r--r--javascripts/Stack.js14
1 files changed, 7 insertions, 7 deletions
diff --git a/javascripts/Stack.js b/javascripts/Stack.js
index c4e2db9..4ccd74e 100644
--- a/javascripts/Stack.js
+++ b/javascripts/Stack.js
@@ -1,19 +1,19 @@
/*
* Stack
- *
+ * Simple implementation of a stack using Array().
*/
function Stack() {
this.a = new Array();
this.length = 0;
};
-//
+// Push an item.
Stack.prototype.push = function(obj) {
this.a.push(obj);
this.length++;
};
-//
+// Pop an item.
Stack.prototype.pop = function() {
if (this.isEmpty()) {
throw('Stack.pop(): Pop from empty stack.');
@@ -22,7 +22,7 @@ Stack.prototype.pop = function() {
return this.a.pop();
};
-//
+// Check if stack is empty.
Stack.prototype.isEmpty = function() {
if (this.length == 0) {
return true;
@@ -30,12 +30,12 @@ Stack.prototype.isEmpty = function() {
return false;
};
-//
+// Get an item at position index.
Stack.prototype.get = function(index) {
return this.a[index];
};
-//
+// Deep copy a stack.
Stack.prototype.copy = function() {
var c = ((new Array()).concat(this.a));
var ret = new Stack();
@@ -44,7 +44,7 @@ Stack.prototype.copy = function() {
return ret;
};
-//
+// String representation.
Stack.prototype.str = function(separator) {
if (!separator) { separator=' ' };
var a = new Array();