#include <iostream>
using namespace std;
template <typename T>
class Stack
{
private:
T data[20];
int top;
public:
Stack() :top(-1), data() {}
bool isFull()
{
if (top == 20)
{
cout << "Stack Full" << endl;
return true;
}
return false;
}
bool isEmpty()
{
if (top == -1)
{
cout << "Stack Empty" << endl;
return true;
}
return false;
}
void pushStack(T data)
{
if (isFull()) return;
top++;
this->data[top] = data;
}
void popStack()
{
if (isEmpty()) return;
top--;
}
void putStack()
{
int t = top;
while (t>=0)
{
cout << data[t] << endl;
t--;
}
}
};
int arr[10];
void hello(int* arr,int index)
{
if (index >= 10)
throw out_of_range("out of range");
cout << arr[index];
}
int main()
{
Stack <int>s;
s.pushStack(1);
s.pushStack(2);
s.pushStack(3);
s.putStack();
try
{
hello(arr,12);
}
catch (const std::out_of_range& o)
{
cout << "biubiu " << o.what();
}
return 0;
}
C++4.2
2024-04-17 21:12:44