We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
delete_stack
1 parent e5dad3f commit 2958609Copy full SHA for 2958609
data_structures/stack/dynamic_stack.c
@@ -192,6 +192,20 @@ int isempty(DArrayStack *ptr)
192
*/
193
int stack_size(DArrayStack *ptr) { return ptr->top + 1; }
194
195
+/**
196
+* @brief Deallocates memory associated with a given DArrayStack.
197
+*
198
+* @param ptr Pointer to the stack structure to be deallocated.
199
+*/
200
+void delete_stack(DArrayStack *const ptr)
201
+{
202
+ if (ptr == NULL) {
203
+ return;
204
+ }
205
+ free(ptr->arrPtr);
206
+ free(ptr);
207
+}
208
+
209
/**
210
* @brief Self-test implementations
211
* @returns void
@@ -237,6 +251,7 @@ static void test()
237
251
238
252
printf("\nTesting POP operation on empty stack: ");
239
253
assert(pop(NewStack) == -1);
254
+ delete_stack(NewStack);
240
255
}
241
256
242
257
0 commit comments