U E D R , A S I H C RSS

스택/Leonardong

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

첫번째 방법
~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;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-05-27 07:09:19
Processing time 0.0079 sec