Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- struct stack_s
- {
- int number;
- struct stack_s *next;
- };
- void push ( int element, struct stack_s **top )
- {
- struct stack_s *p;
- p = *top;
- *top = (struct stack_s *)malloc ( sizeof ( struct stack_s ) );
- (*top)->number = element;
- (*top)->next = p;
- }
- int pop ( struct stack_s **top )
- {
- int element = 0;
- struct stack_s *p;
- if (*top != NULL)
- {
- p = *top;
- element = (*top)->number;
- *top = (*top)->next;
- free ( p );
- }
- return element;
- }
- int main ( ) {
- struct stack_s *top = NULL;
- push ( 1, &top );
- push ( 2, &top );
- push ( 3, &top );
- int a = pop ( &top );
- int b = pop ( &top );
- int c = pop ( &top );
- printf ( "%d,%d,%d\n", c, b, a );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement