데블스 캠프 둘째 날 스택 코드

첫번째 방법
~cpp 
#include <iostream>
using namespace std;
void show_menu();
void push_num();
void pop_num();
void show_num();
const int Asize = 3;
int container[Asize]={0,};
int order=0;

int main()
{
	show_menu();
	return 0;
}

void show_menu()
{
	int choice;
	
	while(true)
	{
		cout << "1 : Push \t 2 : Pop \t 3: Show" << endl;
		cin >> choice;

		switch(choice)
		{
			case 1 : push_num();
					 break;
			case 2 : pop_num();
					 break;
			case 3 : show_num();
					 break;
			default : cout << "눈 똑바로......" << endl;
		}
	}
}

void push_num()
{
	if (order>=Asize)
	{
		cout << "입력 초과" << endl;
		show_menu();
	}

	cout << "입력 : ";
	cin >> container[order++];
}

void pop_num()
{	
	if (order<=0)
	{
		cout << "자료 없음" << endl;
		show_menu();
	}
	container[--order]=0;
}

void show_num()
{
	cout << "자료 : ";
	for (int i=0 ; i<order ; i++)
		cout << container[i] << " ";
	cout << endl;
}

StackAndQueue 데블스캠프2003/둘째날
Retrieved from http://wiki.zeropage.org/wiki.php/스택/Leonardong
last modified 2021-02-07 05:30:16