summaryrefslogtreecommitdiff
path: root/javascripts/Stack.js
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2010-05-18 08:52:24 +0200
committerPatrick Simianer <p@simianer.de>2010-05-18 08:52:24 +0200
commitb90042ebc1f37fa5f911df54ce0d3827da074892 (patch)
tree271ffd81ccf00888380b8b578d9bf238d8e4387b /javascripts/Stack.js
parentec3f1801c258dbba07dfccbd9864f9b2de0bfae6 (diff)
major
Diffstat (limited to 'javascripts/Stack.js')
-rw-r--r--javascripts/Stack.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/javascripts/Stack.js b/javascripts/Stack.js
new file mode 100644
index 0000000..808dea9
--- /dev/null
+++ b/javascripts/Stack.js
@@ -0,0 +1,48 @@
+/*
+ * Stack
+ *
+ */
+function Stack() {
+ 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.');
+ }
+ 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 = '';
+ for (var i=0; i < this.length; i++) {
+ ret += this.a[i].id + ' ';
+ }
+ return ret;
+}