Sie sind auf Seite 1von 4

#include <iostream.

h>
#include <conio.h>
#include <process.h>
#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
void stackk();
void menu();
class Stack
{
private:
int Top, NewItem, Item,N;
int Stc[20];
char c[20];
public:
void Create();
void Push();
void Pop();
void Delete();
void Empty();
void Full();
Stack()
{
Top=-1;
}
};
void Stack ::Create()
{
stackk();
menu();
N=5;
cout<<"\n\n\t\t STACK IS CREATED "<<endl<<endl;
}
void Stack::Push()
{
int j=210;
stackk();
menu();
cout<<"\n\n\t\t PUSH STACK "<<endl<<endl;
if ( Top >= N )
{
cout<<"\n Over Flow";
}
else
{
Top=Top+1;
cout<<"\nEnter a number : ";
cin>>NewItem;
Stc[Top] = NewItem;
cout<<"\nItem Stored";
}
for(int i=0;i<=Top;i++)
{
outtextxy(550,j,itoa(Stc[i],c,10));
j=j-30;
}
//getch();

}
void Stack::Pop()
{
stackk();
menu();
int j=210;
cout<<"\n\n\t\t POP STACK "<<endl<<endl;

if ( Top == -1 )
{
cout<<"\nUnderflow";
}
else
{
Stc[Top] = Item;
Top=Top-1;
cout<<"\nItem Deleted";
}
for(int i=0; i<=Top; i++)
{
outtextxy(550,j,itoa(Stc[i],c,10));
j=j-30;
}
}
void Stack::Empty()
{
cout<<"\n\n\t\t EMPTY STACK "<<endl<<endl;
if ( Top == 0 )
{
cout<<"\n\n Empty;"<<endl;
}
else
cout<<"\n\n Not empty"<<endl;
}
void Stack::Full()
{
cout<<"\n\n\t\t FULL STACK "<<endl<<endl;

if ( Top >= N )
{
cout<<"\n\n Full "<<endl;
}
else
cout<<"\n\n Not Full"<<endl;
}
void main()
{
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "..\\bgi");
char ch,choice;
Stack st;

do
{
menu();
cout<<"\n\n Seclect Choice "<<endl<<endl;
cin>>ch;
switch(ch)
{
case '1':
st.Create();
break;
case '2':
st.Push();
break;
case '3':
st.Pop();
break;
case '4':
st.Empty();
break;
case '5':
st.Full();
break;
default:
cout<<"\n\n Wrong choice entered "<<endl;
}
cout<<"\n\n\n\ndo you want to see the main menu again";
cin>>choice;
}while(choice=='y');

getch();
}
void menu()
{
settextstyle(11,0,1);
{
setbkcolor(15);
setcolor(8);
outtextxy(10,240,"press 1 for creating stack");
outtextxy(10,270,"press 2 for push stack");
outtextxy(10,300,"press 3 for pop stack");
outtextxy(10,330,"press 4 for full stack");
outtextxy(10,360,"press 5 for empty stack");
outtextxy(10,400,"press 6 for destroy stack");
}
}
void stackk()
{
int graphdriver = DETECT, graphmode;
initgraph(&graphdriver, &graphmode, "..\\bgi");
setcolor(8);
rectangle(0,0,620,230);
line(600,10,600,220);
line(500,10,500,220);
line(600,220,500,220);
line(600,190,500,190);
line(600,160,500,160);
line(600,130,500,130);
line(600,100,500,100);
line(600,70,500,70);
line(600,40,500,40);
}

Das könnte Ihnen auch gefallen