[c] hvg

Viewer

  1. #include<stdio.h>
  2. int t, top = -1, max = 1,,j, q;
  3. int a[2];
  4. char x,e,d,w;
  5.  
  6. int full()
  7. {
  8.     if ((top+1) > max) return 1;
  9.     else return 0;
  10. }
  11. int empty()
  12. {
  13.     if (top <= -1) return 1;
  14.     else return 0;
  15. }
  16. int main()
  17. {
  18.     //int t, top = -1, max = 2,i;
  19.     scanf("%d",&t);
  20.     //char q;
  21.     //scanf("%c",&d);
  22.     //int a[2];
  23.     for (j=0; j<t; j++)
  24.     {
  25.         //char x,w,e;
  26.         //int q;
  27.         scanf("%c",&x);
  28.         //scanf("%w",&w);
  29.  
  30.         if (== 'i')
  31.         {
  32.             scanf("%d",&q);
  33.             //scanf("%c",&e);
  34.  
  35.             if (full())
  36.             {
  37.                 printf("overflow\n");
  38.                 for (i=0; i <= top; i++) printf("%d ",a[i]);
  39.                 printf("\n");
  40.             }
  41.             else
  42.             {
  43.                 top++;
  44.                 a[top] = q;
  45.                 for (i=0; i<=top; i++) printf("%d ",a[i]);
  46.                 printf("\n");
  47.             }
  48.         }
  49.         else if (== 'd')
  50.         {
  51.             if (empty())
  52.             {
  53.                 printf("underflow\n");
  54.                 //for (i=0; i<=top; i++) printf("%d",a[i]);
  55.             }
  56.             else
  57.             {
  58.                 top--;
  59.                 if (top < 0)
  60.                 {
  61.                     printf("empty\n");
  62.                 }
  63.                 else
  64.                 {
  65.                     for (i=0; i<=top; i++)
  66.                     {
  67.                         printf("%d ",a[i]);
  68.                         printf("\n");
  69.                     }
  70.                 }
  71.  
  72.             }
  73.         }
  74.  
  75.     }
  76. }
  77.  

Editor

You can edit this paste and save as new:


File Description
  • hvg
  • Paste Code
  • 23 Mar-2023
  • 1.56 Kb
You can Share it: