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