C++4.2

#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;
    
}

相关推荐

  1. c yuv422转yuv420p

    2024-04-04 12:02:03       54 阅读
  2. 学完Efficient c++ (44-45)

    2024-04-04 12:02:03       40 阅读
  3. 学完Efficient c++ (46-47)

    2024-04-04 12:02:03       44 阅读
  4. 《Effective Modern C++》- 极精简版 36-42

    2024-04-04 12:02:03       40 阅读
  5. C:2019-42真题408 循环队列

    2024-04-04 12:02:03       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-04 12:02:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-04 12:02:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-04-04 12:02:03       82 阅读
  4. Python语言-面向对象

    2024-04-04 12:02:03       91 阅读

热门阅读

  1. os模块篇(十二)

    2024-04-04 12:02:03       32 阅读
  2. 5.108 BCC工具之virtiostat.py解读

    2024-04-04 12:02:03       36 阅读
  3. .net 实现的 Webscoket 对象的一些细节和疑问

    2024-04-04 12:02:03       41 阅读
  4. Ideal Holidays

    2024-04-04 12:02:03       38 阅读
  5. Sora文本生成视频(附免费的专属提示词)

    2024-04-04 12:02:03       41 阅读
  6. PyTorch示例——使用Transformer写古诗

    2024-04-04 12:02:03       31 阅读