#include<iostream>
using namespace std;
int stack[10001];
int index = -1;
void push(int data)
{
if(index == 10000)
cout << "inaccessible" << "\n";
else
stack[++index] = data;
}
void pop()
{
if (index == -1)
cout << "inaccessible" << "\n";
else
stack[index--] = 0;
}
int size()
{
return index + 1;
}
bool empty()
{
if (index == -1)
return true;
else
return false;
}
int top()
{
return stack[index];
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
string order;
int x;
while (true)
{
cin >> order;
if (order == "push")
{
cin >> x;
push(x);
}
else if (order == "pop")
pop();
else if (order == "size")
cout << "size : " << size() << "\n";
else if (order == "empty")
{
if (empty())
cout << "Stack is Empty" << "\n";
else
cout << "False" << "\n";
}
else if (order == "top")
cout << "top : " << top() << "\n";
else if (order == "print")
{
cout << "stack : ";
for (int i = 0; i <= index; i++)
{
cout << stack[i] << " ";
}
cout << "\n";
}
else if (order == "end")
break;
else
cout << "InValid Input" << "\n";
}
}
'> CS' 카테고리의 다른 글
[컴퓨터 구조] 캐시 메모리, 주기억장치 (0) | 2023.08.08 |
---|---|
[컴퓨터 구조] 기억 장치 (0) | 2023.07.20 |
[컴퓨터 구조] 병렬 처리, 메모리 공유방식 (0) | 2023.07.12 |
[컴퓨터 구조] 시스템 구성 요소, CPU와 GPU (0) | 2023.07.11 |
[알고리즘] 삽입 정렬(Insertion Sort) 구현 (C++) (0) | 2023.06.08 |