Skip to content

Instantly share code, notes, and snippets.

@devansh42
Created August 16, 2019 18:45
Show Gist options
  • Save devansh42/b14ba561f675581e9aace0ff41ff0919 to your computer and use it in GitHub Desktop.
Save devansh42/b14ba561f675581e9aace0ff41ff0919 to your computer and use it in GitHub Desktop.
#include "stack.h"
#include<stdlib.h>
BasicStack* new_basic_stack(int cap){
BasicStack* s;
//Allocating memory for Basic Stack Structure
s=(BasicStack*)malloc(sizeof(BasicStack));
//Allocating memory for Array used to hold stack
s->ar=malloc(sizeof(int)*cap);
//Setting capcity of stack
s->cap=cap;
//Setting intial size of stack
s->size=0;
return s;
}
void delete_basic_stack(BasicStack* s){
//Freeing memory associated with array containing stack
free(s->ar);
//Freeing memory associated with BasicStack struct
free(s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment