Skip to content
Snippets Groups Projects
Select Git revision
  • 6ec3c8eab52515c7709969b35fcf28fdef150a4c
  • main default protected
  • 3-add-makefile-with-structure
  • 9-add-destroy-function-4
  • 4-add-create-init-function
  • 5-add-push-function-2
  • 9-add-destroy-function-3
  • 9-add-destroy-function-2
  • v0.1
9 results

stack.h

Blame
  • stack.c 379 B
    #include <stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    #include <stdbool.h>
    
    #define DEFAULT_CAPACITY 4
    
    typedef struct _stack {
        int *data;
        int capacity;
        int top;
    } stack;
    
    // depile
    void stack_pop(stack *s, int *value){
    	assert(s->top>=0 && "Stcak is empty\n");	
    
    	if (s->top == s->capacity/4){
    		s->capacity /= 2;
    	}
    	
    	*value = s->data[s->top];
    	s->top -= 1;
    }