30 lines
584 B
Plaintext
30 lines
584 B
Plaintext
Stack :: struct(Value_Type : Type) {
|
|
values: [..] Value_Type;
|
|
}
|
|
|
|
stack_push :: (stack: *Stack, value: stack.Value_Type) {
|
|
array_add(*stack.values, value);
|
|
}
|
|
|
|
stack_pop :: (stack: *Stack) -> stack.Value_Type {
|
|
if stack.values.count > 0 {
|
|
index := stack.values.count - 1;
|
|
stack.values.count -= 1;
|
|
return stack.values.data[index];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
stack_peek :: (stack: *Stack) -> stack.Value_Type {
|
|
if stack.values.count > 0 {
|
|
return stack.values[stack.values.count-1];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
is_stack_empty :: (stack: *Stack) -> bool {
|
|
return stack.values.count == 0;
|
|
}
|