Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- int stack[100],top=-1,flag=0;
- void push(int x)
- {
- if(top==99 || top>99){
- printf("stack overflow\n");
- }
- else stack[++top]=x;
- }
- int pop()
- {
- if(top<0){
- flag++;
- return 0;
- }
- else{
- return stack[top--];
- }
- }
- int main()
- {
- int n,i,x;
- for(i=1;i<3;i++)
- {
- printf("Number of data: ");
- scanf("%d",&n);
- printf("\n");
- while(n--){
- scanf("%d",&x);
- push(x);
- }
- printf("how many data to display: ");
- scanf("%d",&n);
- printf("\n");
- while(n--){
- x=pop();
- if(flag==0){
- printf("Data = %d\n",x);
- }
- else{
- printf("Stack is empty\n");
- }
- }
- top=-1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement