Skip to content
Snippets Groups Projects
Commit 7c4c3829 authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Added quick_pop().

The initial stack size can now be specified to create() and reset().

Rev: lib/modules/Stack.pmod:1.4
parent 016b4ba6
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,14 @@
class stack {
int ptr;
mixed *arr=allocate(32);
mixed *arr;
void push(mixed val)
{
if(ptr==sizeof(arr)) arr+=allocate(ptr);
arr[ptr++]=val;
if(ptr == sizeof(arr)) {
arr += allocate(ptr);
}
arr[ptr++] = val;
}
mixed top()
......@@ -18,6 +20,21 @@ class stack {
error("Stack underflow\n");
}
void quick_pop(void|int val)
{
if (val) {
if (ptr < val) {
ptr = 0;
} else {
ptr -= val;
}
} else {
if (ptr > 0) {
ptr--;
}
}
}
mixed pop(void|int val)
{
mixed foo;
......@@ -46,10 +63,15 @@ class stack {
return foo;
}
void reset()
void reset(int|void initial_size)
{
arr = allocate(initial_size || 32);
ptr = 0;
}
void create(int|void initial_size)
{
arr=allocate(32);
ptr=0;
arr = allocate(initial_size || 32);
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment