SAADQUAMER

Untitled

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