Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // not finnished
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct node {
- int data;
- struct node *next;
- } stack;
- stack* init() {
- stack* tmp = malloc(sizeof(stack));
- tmp->data = NULL;
- tmp->next = NULL;
- return tmp;
- }
- void destroy(stack **s) {
- *s = NULL;
- }
- int push(stack** s, int value) {
- if (s == NULL) return 0;
- if((*s)->data == NULL) {
- (*s)->data = value;
- }
- else {
- stack* tmp = malloc(sizeof(stack));
- tmp->data = value;
- tmp->next = *s;
- *s = tmp;
- }
- return 1;
- }
- int pop(stack** s) {
- if (s == NULL) return NULL;
- int value = (*s)->data;
- *s = (*s)->next;
- return value;
- }
- int main() {
- stack* st1 = init();
- push(&st1, 1);
- push(&st1, 2);
- //push(st1, 3);
- printf("%d\n", st1->data);
- pop(&st1);
- printf("%d\n", st1->data);
- //destroy(st1);
- }
Advertisement
Add Comment
Please, Sign In to add comment