Guest User

Untitled

a guest
Feb 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. struct El {
  6. int d;
  7. El *next;
  8. };
  9.  
  10. El *top = NULL;
  11.  
  12. void add ( int x ) {
  13. El *t = (El*)malloc(sizeof(El));
  14. if (top == NULL){
  15. t->d = x;
  16. t->next = NULL;
  17. top = t;
  18. } else {
  19. t->d = x;
  20. t->next = top;
  21. top = t;
  22. }
  23. }
  24.  
  25. int pop ( ){
  26. El *x;
  27. int d;
  28. x = top;
  29. d = top->d;
  30. top = top->next;
  31. free(x);
  32. return d;
  33. }
  34.  
  35. int main(){
  36. add(1);
  37. add(2);
  38. add(3);
  39. printf("%d\n",pop());
  40. printf("%d\n",pop());
  41. printf("%d\n",pop());
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment