First commit

This commit is contained in:
2017-01-24 13:17:59 +01:00
commit b49c1e543f
9 changed files with 260 additions and 0 deletions

39
stack.cpp Normal file
View File

@@ -0,0 +1,39 @@
#include "stack.h"
#include <stdlib.h>
t_stack stack_new(const int size) {
t_stack stack;
stack.max = size;
stack.top = -1;
stack.data = (unsigned char*)malloc(size);
return stack;
}
const bool stack_isempty(t_stack& stack) {
return stack.top == -1;
}
const bool stack_isfull(t_stack& stack) {
return stack.top == stack.max;
}
void stack_push(t_stack& stack, const char value) {
if (!stack_isfull(stack)) {
stack.data[++stack.top] = value;
}
}
const char stack_pop(t_stack& stack) {
if (!stack_isempty(stack)) {
return stack.data[stack.top--];
}
}
const char stack_peek(t_stack& stack) {
return stack.data[stack.top];
}
void stack_delete(t_stack& stack) {
free(stack.data);
}