summaryrefslogtreecommitdiff
path: root/javascripts/Stack.js
diff options
context:
space:
mode:
Diffstat (limited to 'javascripts/Stack.js')
-rw-r--r--javascripts/Stack.js39
1 files changed, 23 insertions, 16 deletions
diff --git a/javascripts/Stack.js b/javascripts/Stack.js
index 808dea9..c4e2db9 100644
--- a/javascripts/Stack.js
+++ b/javascripts/Stack.js
@@ -3,46 +3,53 @@
*
*/
function Stack() {
- this.a = new Array();
+ this.a = new Array();
this.length = 0;
-}
+};
+//
Stack.prototype.push = function(obj) {
this.a.push(obj);
this.length++;
-}
+};
+//
Stack.prototype.pop = function() {
if (this.isEmpty()) {
- throw('Pop from empty stack.');
- }
+ throw('Stack.pop(): Pop from empty stack.');
+ };
this.length--;
return this.a.pop();
-}
+};
+//
Stack.prototype.isEmpty = function() {
if (this.length == 0) {
return true;
- }
+ };
return false;
-}
+};
+//
Stack.prototype.get = function(index) {
return this.a[index];
-}
+};
+//
Stack.prototype.copy = function() {
var c = ((new Array()).concat(this.a));
var ret = new Stack();
ret.a = c;
ret.length = this.length;
return ret;
-}
+};
-Stack.prototype.str = function() {
- ret = '';
+//
+Stack.prototype.str = function(separator) {
+ if (!separator) { separator=' ' };
+ var a = new Array();
for (var i=0; i < this.length; i++) {
- ret += this.a[i].id + ' ';
- }
- return ret;
-}
+ a.push(this.a[i].id);
+ };
+ return a.join(separator);
+};