2
[CCode (cname = "VStack", cprefix = "v_stack_")]
3
public class Stack <T> {
4
private static int step_size = 11;
7
public size_t elements {get {return pntr + 1;}}
10
public Stack (size_t size = 23) {
11
this.stack = new T[size];
16
public void push (T val) {
18
this.stack[this.pntr] = val;
19
if (this.pntr + 1 >= this.size) {
20
this.stack.resize (this.stack.length + Stack.step_size);
26
info ("Tryinng to pop value from empty Stack:\n" +
30
T ret_val = this.stack[this.pntr];
31
this.stack[this.pntr] = null;
36
public bool is_empty () {
37
return (this.pntr == -1);
44
public T peek_n (size_t n) {
46
info ("Trying to peek a value from empty Stack:\n" +
50
if ((this.pntr - n) <= 0) {
53
return this.stack[this.pntr - n];