Monday, July 02, 2018

[TCS] stack program through array (CodeVita) Problem [Solved]

Solution:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 50
int top=-1;
int stack[MAX];
int push(x)
{    if(top==MAX)
{
     printf("stack is full\n");
     return 0;
     }
     stack[top+1]=x;
     top++;
     return 1;
}
int pop()
{   if(top==-1)
{
    printf("stack is empty\n");
    getch(); 
    exit(0);
}
    int temp;
    temp=stack[top];
    top--;
    return temp;
}
int main()
{
    int x,y;
    while(x!=0)
    {
    printf("enter 1 to push 2 to pop 0 to exit");
    scanf("%d",&x);
    if(x==1)
    {
            printf("enter data\n");
            scanf("%d",&y);
            push(y);
}
if(x==2)
{
        y=pop();
        printf(" %d poped\n",y);
        }
        }
        getch();
        }
www.matterhere.com - Nareddula Rajeev Reddy (NRR)
Programming Geek
Source: programmaniaa blog.

*To get the more, view the [TCS] stack program through array (CodeVita) Problem [Solved]. These are only for reference purpose.

* Ask us, what you want?
EmoticonEmoticon