Stack usingan array
#include<iostream .h>
#include <conio.h>
#define ms5
Class stack
{
Int a[ms],size ,top;
Public:
Stack(int n);
{
Size =n;
Top=-1;
}
Void push();
Void push();
Void display();
};
Void stack::push()
{
Int x;
If(top<=size-1)
{
Cout<<”enter the value”;
Cin>>x;
top++;
a[top]=x;
}
else
cout<<”stackis overflow”;
}
Void stack::pop()
{
int y;
if(top==-1)
cout<<”stackis empty”;
else
{
Y=a[top];
Cout<<”the deletedvalue is :”<< y;
Top--;
}
}
Void stack ::display()
{
Int i;
If (top==-1)
Cout<<”stackis empty”;
Else
{
Cout<<”stackis empty“;
Else
{
cout <<”the element of stack”;
for

Ds program

  • 1.
    Stack usingan array #include<iostream.h> #include <conio.h> #define ms5 Class stack { Int a[ms],size ,top; Public: Stack(int n); { Size =n; Top=-1; } Void push(); Void push(); Void display(); }; Void stack::push() { Int x; If(top<=size-1) { Cout<<”enter the value”; Cin>>x; top++; a[top]=x; } else cout<<”stackis overflow”; } Void stack::pop() { int y; if(top==-1)
  • 2.
    cout<<”stackis empty”; else { Y=a[top]; Cout<<”the deletedvalueis :”<< y; Top--; } } Void stack ::display() { Int i; If (top==-1) Cout<<”stackis empty”; Else { Cout<<”stackis empty“; Else { cout <<”the element of stack”; for