Initial commit
This commit is contained in:
29
core/stack.jai
Normal file
29
core/stack.jai
Normal file
@@ -0,0 +1,29 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user