Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stack.h"
- #include <inttypes.h>
- Stack theStack;
- StackError_t init()
- {
- if (STACK_SIZE == 0)
- return StackError_t::STACK_INIT_ERROR;
- for( size_t i = 0; i < STACK_SIZE; ++i )
- theStack.data[ i ] = 0;
- theStack.length = 0;
- return StackError_t::STACK_NO_ERROR;
- }
- StackError_t push(uint8_t value)
- {
- if (theStack.length < STACK_SIZE)
- {
- theStack.data[STACK_SIZE - ++theStack.length] = value;
- return StackError_t::STACK_NO_ERROR;
- }
- else
- return StackError_t::STACK_OVERFLOW_ERROR;
- }
- StackError_t pop( uint8_t* value )
- {
- if (theStack.length > 0)
- {
- *value = theStack.data[STACK_SIZE - theStack.length--];
- return StackError_t::STACK_NO_ERROR;
- }
- else
- return StackError_t::STACK_UNDERFLOW_ERROR;
- }
- StackError_t peek(const uint8_t* index)
- {
- for (size_t i = 0; i < theStack.length; ++i)
- if (theStack.data[i] == *index)
- return StackError_t::STACK_NO_ERROR;
- return StackError_t::STACK_VALUE_NOT_FOUND;
- }
- bool isEmpty()
- {
- if (theStack.length == 0)
- return true;
- return false;
- }
- bool isFull()
- {
- if (theStack.length == STACK_SIZE)
- return true;
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement