

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 8
click for more info
Not enough gems
Cost: 6 gems
1: Low Level Stack
incomplete
2: Stack Push
incomplete
3: Stack Pop
incomplete
4: Stack free
incomplete
5: Dangerous Push
incomplete
6: Multiple Types
incomplete
This lesson's interactive features are locked, please to keep using them
If you've taken our data structures course, you've already implemented a stack. We're going to implement a stack again, but this time we're going to do it while manually managing the memory of generic pointers!
We'll get to have our first deeper exploration of "generics" in C (remember, that just means void *) as well as creating a data structure we will later use in our mark-and-sweep garbage collector.
Take a look at snekstack.h, specifically the Stack struct.
count is the number of elements in the stack.capacity is the number of elements the stack can hold before it needs to be resized in memory.data is a pointer to all the generic data.Implement the stack_new function: