I'm curious about how to delete a struct that I stored in a list. I tried this code but it gives me a segmentation fault error and I can't see the mistake.
typedef struct double_stack_head_struct
{
struct double_stack_head_struct* tail;
double value;
} double_stack_head;
typedef struct double_stack_struct // the structure containing the state of a stack
{
int size; // size of stack
double_stack_head* head;
} double_stack;
void push_double_stack(double_stack* stack, double value)
{
double_stack_head* new_head = malloc(sizeof(double_stack_head));
if(new_head != NULL) {
new_head->tail = stack->head;
new_head->value = value;
stack->head = new_head;
stack->size += 1;
}
}
int pop_double_stack(double_stack* stack, double* value)
{
if(empty_double_stack(stack)) {
return false;
} else {
*value = stack->head->value;
free(stack->head);
stack->size -= 1;
stack->head = malloc(sizeof(stack->head));
stack->head = stack->head->tail;
return true;
}
}