fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct Stack{
  4. int data;
  5. struct Stack* next;
  6. }Stack;
  7.  
  8. void push(Stack*, int);
  9. int pop(Stack*);
  10.  
  11. int main(){
  12. Stack* top=NULL;
  13.  
  14. push(top,2);
  15. printf("push %d \n",top->data);
  16.  
  17. push(top,3);
  18. printf("push %d \n",top->data);
  19.  
  20. push(top,1);
  21. printf("push %d \n",top->data);
  22.  
  23. printf("pop %d \n",pop(top));
  24. printf("pop %d \n",pop(top));
  25. printf("pop %d \n",pop(top));
  26. printf("pop %d \n",pop(top));
  27. return 0;
  28. }
  29.  
  30.  
  31. void push(Stack* top,int n){
  32. Stack* node = (Stack*)malloc(sizeof(Stack));
  33. node->data=n;
  34. node->next=top;
  35. top=node;
  36. }
  37.  
  38. int pop(Stack* top){
  39. int n=top->data;
  40. Stack* node=top;
  41. top=top->next;
  42. free(node);
  43. return n;
  44. }
Runtime error #stdin #stdout 0s 2164KB
stdin
Standard input is empty
stdout
Standard output is empty