SAADQUAMER

Stack

Dec 9th, 2019
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define CAPACITY 1000
  5. typedef struct node
  6. {
  7. int data;
  8. struct node *next;
  9. struct node *prev;
  10. } node ;
  11. node*top=NULL,*tail;
  12.  
  13. int size = 0;
  14.  
  15. void push(int element)
  16.  
  17. {
  18. node *N = (node *) malloc(sizeof(node));
  19. N->data = element;
  20.  
  21. N->next =NULL;
  22. N->prev =NULL;
  23.  
  24. if(top==NULL)
  25. {
  26. top=N;
  27. tail=N;
  28. }
  29. else
  30. {
  31. top->next=N;
  32. N->prev=top;
  33. top=N;
  34. ++size;
  35.  
  36. }
  37. }
  38. int pop()
  39. {
  40. int data=0;
  41. node*temp;
  42. temp=top;
  43. data=top->data;
  44. top=top->prev;
  45. free(temp);
  46. size--;
  47. return data;
  48. }
  49.  
  50.  
  51. int main()
  52. {
  53.  
  54. int t,data,i;
  55. int m,l,x;
  56.  
  57. printf("TOTAL INPUT :");
  58. scanf("%d",&t);
  59. for(i=0; i<t; i++)
  60. {
  61. scanf("%d",&data);
  62. push(data);
  63. }
  64.  
  65. printf("\nOutput:\n");
  66. for(l=0; l<t; l++)
  67. {
  68. x=pop();
  69. printf("%d\n",x);
  70. }
  71.  
  72.  
  73. }
RAW Paste Data