Skip to content

Instantly share code, notes, and snippets.

@ibeauregard
Created April 2, 2021 22:29
Show Gist options
  • Save ibeauregard/5c006a21ae0f47a23094c3980f557a33 to your computer and use it in GitHub Desktop.
Save ibeauregard/5c006a21ae0f47a23094c3980f557a33 to your computer and use it in GitHub Desktop.
/* int_stack.c */
#include "int_stack.h"
typedef struct int_node IntNode;
struct internals {
IntNode* top;
};
// ...
IntStack* new_stack()
{
IntStack* this = malloc(sizeof (IntStack));
this->_internals = malloc(sizeof (struct internals));
this->_internals->top = NULL;
// Function pointer assignments
return this;
}
// ...
void push(IntStack* this, int value)
{
IntNode* pushed = malloc(sizeof (IntNode));
pushed->value = value;
pushed->next = this->_internals->top; // top is not tied directly to this anymore
this->_internals->top = pushed;
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment