Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- File Edit Options Buffers Tools C Help
- #include "stack.h"
- #include <stdlib.h>
- #include <stdio.h>
- void stack_init(stack_s *stack) {
- *stack = malloc(sizeof(stack_node_s));
- (*stack)->next = NULL;
- (*stack)->value = NULL;
- }
- int stack_push(void *p, stack_s *stack) {
- stack_s first = malloc(sizeof(stack_node_s));
- if (first == NULL) {
- return -1;
- } else {
- first->value = p;
- first->next = *stack;
- *stack = first;
- return 1;
- }
- }
- void *stack_pop(stack_s *stack) {
- if (*stack != NULL) {
- void *temp = malloc(sizeof(void));
- *temp = (*stack)->value;
- *stack = (*stack)->next;
- return *temp;
- } else {
- return NULL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement