Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by oopc-8 on 26.09.16.
- //
- #include "int_stack.h"
- void init(tStack *s) {
- tStackElement *newContent;
- newContent = (tStackElement) malloc(sizeof(tStackElement));
- if (newContent == NULL) {
- printf("Insufficient memory");
- return -1;
- }
- s->content = newContent;
- s->top = -1;
- }
- void destroy(tStack *s) {
- free(s->content);
- s->content = NULL;
- s->top = -1;
- }
- int isEmpty(tStack s) {
- if (s.top < 0) {
- return 1;
- } else {
- return 0;
- }
- }
- int isFull(tStack s) {
- if (s.top >= s.maxSize - 1) {
- return 1;
- } else {
- return 0;
- }
- }
- int push(tStack *s,tStackElement el) {
- s->top++;
- s->content = (tStackElement) realloc(s->content, sizeof(tStackElement) * (top + 1));
- s->content[s->top] = el;
- return 1;
- }
- tStackElement pop(tStack *s){
- if (isEmpty(s)) {
- printf("Cannot pop element, cause stack is empty");
- return -1;
- }
- return s->content[s->top--];
- }
Advertisement
Add Comment
Please, Sign In to add comment