IT/[Everyday]Coding
[C++] 클래스로 LIFO(스택) 구현하기
Jang HyunWoong
2014. 12. 19. 10:20
#include "iostream.h"
class classLIFO
{
private : int top;
public :
void LIFO()
{
top = 0;
};
void push(int x)
{
top = top + x;
};
void pop(int y)
{
top = top - y;
if(top <= 0)
{
cout << "It's empty!\n";
top = 0;
}
};
void total()
{
cout << "Top : " << top << "\n";
};
};
void main()
{
int Nompush=0;
int Nompop=0;
cout << "\nInput some push numbers:";
cin >> Nompush;
cout << "Input some pop numbers:";
cin >> Nompop;
classLIFO stack01;
stack01.LIFO();
stack01.push(Nompush);
stack01.pop(Nompop);
stack01.total();
}
반응형