PROGRAM FOR STACK DS IN C++
//program for stack
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int top=-1;
struct stack
{
char a[10];
}sat;
void push(stack s,char a)
{
top++;
s.a[top]=a;
}
char pop(stack s)
{
char c=s.a[top];
top--;
return c;
}
int isempty(stack s)
{
if(top==-1)
return 1;
else
return 0;
}
int isfull(stack s)
{
if(top==9)
return 1;
else
return 0;
}
void main()
{
char b[5];
int i;
clrscr();
cout<<"enter the input:";
gets(b);
for(i=0;b[i]!='\0';i++)
{
push(sat,b[i]);
pop(sat);
}
if(isempty(sat))
cout<<"stack is empty";
else
cout<<"stack is not empty";
getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int top=-1;
struct stack
{
char a[10];
}sat;
void push(stack s,char a)
{
top++;
s.a[top]=a;
}
char pop(stack s)
{
char c=s.a[top];
top--;
return c;
}
int isempty(stack s)
{
if(top==-1)
return 1;
else
return 0;
}
int isfull(stack s)
{
if(top==9)
return 1;
else
return 0;
}
void main()
{
char b[5];
int i;
clrscr();
cout<<"enter the input:";
gets(b);
for(i=0;b[i]!='\0';i++)
{
push(sat,b[i]);
pop(sat);
}
if(isempty(sat))
cout<<"stack is empty";
else
cout<<"stack is not empty";
getch();
}

Comments
Post a Comment