[c] hvg
Viewer
- #include<stdio.h>
- int t, top = -1, max = 1,i ,j, q;
- int a[2];
- char x,e,d,w;
- int full()
- {
- if ((top+1) > max) return 1;
- else return 0;
- }
- int empty()
- {
- if (top <= -1) return 1;
- else return 0;
- }
- int main()
- {
- //int t, top = -1, max = 2,i;
- scanf("%d",&t);
- //char q;
- //scanf("%c",&d);
- //int a[2];
- for (j=0; j<t; j++)
- {
- //char x,w,e;
- //int q;
- scanf("%c",&x);
- //scanf("%w",&w);
- if (x == 'i')
- {
- scanf("%d",&q);
- //scanf("%c",&e);
- if (full())
- {
- printf("overflow\n");
- for (i=0; i <= top; i++) printf("%d ",a[i]);
- printf("\n");
- }
- else
- {
- top++;
- a[top] = q;
- for (i=0; i<=top; i++) printf("%d ",a[i]);
- printf("\n");
- }
- }
- else if (x == 'd')
- {
- if (empty())
- {
- printf("underflow\n");
- //for (i=0; i<=top; i++) printf("%d",a[i]);
- }
- else
- {
- top--;
- if (top < 0)
- {
- printf("empty\n");
- }
- else
- {
- for (i=0; i<=top; i++)
- {
- printf("%d ",a[i]);
- printf("\n");
- }
- }
- }
- }
- }
- }
Editor
You can edit this paste and save as new: