Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //by FamiHug
- #include <stdio.h>
- #define MAX 50
- float a[MAX];
- int t;
- void init_stack();
- int full();
- int empty();
- void push(float);
- float pop();
- int main()
- {
- float y;
- init_stack();
- printf("CHUONG TRINH MINH HOA STACK\n");
- printf("Da khoi tao stack. T=%d\n",t);
- printf("Them vao stack 1 phan tu: ");
- scanf("%f",&y);
- push(y);
- printf("T=%d\n",t);
- printf("Them vao stack 1 phan tu nua: ");
- scanf("%f",&y);
- push(y);
- printf("T=%d\n",t);
- printf("Lay 1 phan tu ra khoi stack.\n");
- y = pop();
- printf("T=%d x=%g\n",t,y);
- return 1;
- }
- void init_stack()
- {
- t=0;
- }
- int full()
- {
- if(t==MAX) return 1;
- else return 0;
- }
- int empty()
- {
- if(t==0) return 1;
- else return 0;
- }
- void push(float x)
- {
- if(full()) printf("\nStack day!");
- else
- {
- a[t] = x;
- t++;
- }
- }
- float pop()
- {
- if(empty())
- {
- printf("\nStack rong!");
- return 0;
- }
- else
- {
- t--;
- return a[t];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement