I've written a very simple linked list based stack implementation and was wondering if this is the standard way to do it in C.
typedef struct Node {
int value;
struct Node *prev;
} Node;
Node * push(Node *top, int value) {
Node *node = (Node *) malloc(sizeof(Node));
node->value = value;
node->prev = top;
return node;
}
Node * pop(Node *top, int *val_addr) {
*val_addr = top->value;
Node *new_top = top->prev;
free(top);
return new_top;
}
int is_empty(Node *top) {
return top == NULL;
}
Before deciding to post on code review I decided to check google for stack implementations to see if mine was okay. But most of the decent sources that I checked used an array implementation. I was wondering in what situation is it better to use a dynamic array based stack?