Skip to content

Instantly share code, notes, and snippets.

@ibeauregard
Last active April 24, 2021 11:20
Show Gist options
  • Save ibeauregard/1bd25a2e47b99ab081107c6a130fb170 to your computer and use it in GitHub Desktop.
Save ibeauregard/1bd25a2e47b99ab081107c6a130fb170 to your computer and use it in GitHub Desktop.
Introduce the destructor
/* int_stack.h */
//...
// Other function declarations
void delete_stack(IntStack** stack);
/* main.c */
#include "int_stack.h"
//...
int main()
{
//...
delete_stack(&stack);
return 0;
}
/* int_stack.c */
#include "int_stack.h"
//...
void delete_stack(IntStack** stack)
{
while (!is_empty_stack(*stack)) {
pop_stack(*stack);
}
free(*stack); *stack = NULL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment