stack.c

lima-1.0b5/lib/contrib/stack.c · 534 B

From the archive lima-1.0b5+driver.tar.gz

Download the archive   « Back to the archive contents

/* Do not remove the headers from this file! see /USAGE for more info. */

class stack {
    int which;
    array elems;
};

class stack stack_new(int size) {
    class stack s = new(class stack);
    s->which = 0;
    s->elems = allocate(size);
    return s;
}

void stack_push(class stack s, mixed item) {
    if (s->which == sizeof(s->elems))
	error("Stack overflow.\n");
    s->elems[s->which++] = item;
}

mixed stack_pop(class stack s) {
    if (s->which == 0)
	error("Stack underflow.\n");
    return s->elems[--(s->which)];
}

Site Stats

Snippets: 1791
Codebases: 571