U E D R , A S I H C RSS

스택/aekae

Stack

~cpp 
#include <iostream>
using namespace std;

void menu();
void push();
void pop();
void show();
void exit();

int arr[10];
int i=0;

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

void menu()
{
	cout << "스택입니다.\n"
			"1. 추가  2. 삭제  3. 보여주기  4. 끝내기 \n"
			"원하는 번호 선택 : ";
	int input;
	cin >> input;
	switch(input)
	{
	case 1: push();
			break;
	case 2: pop();
			break;
	case 3: show();
			break;
	case 4: exit();
			break;
	}
}

void push()
{
	cout << "추가할 값 입력: ";
	cin >> arr[i];
	cout << arr[i] << "추가" << endl;
	i++;
	menu();
}
 
void pop()
{
	cout << arr[--i] << "를 삭제합니다" << endl;
	menu();
}

void show()
{
	for(int j=i-1; j>=0; j--)
		cout << arr[j] << endl;
	menu();
}

void exit()
{
	return;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:30:16
Processing time 0.0104 sec