C++ 作业

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <stack>
using namespace std;
const int INF = 1E9 + 7;
class Stack {
private :
    struct node {
        int key;
        struct node * pre;
        struct node * nexT;
    }*tail;
    int length;
public:
    Stack () {
        tail = NULL;
        length = 0;
    }
    ~Stack () {
        delete tail;
    }
    void push (int x);
    int pop ();
    int top ();
    inline int size () {return length;}
    inline bool empty () {return length == 0;}
};
void Stack:: push (int x) {
    node * temp;
    temp = new (node);
    tail -> nexT = temp;
    temp -> pre = tail;
    tail = temp;
    temp -> key = x;
    tail -> nexT = NULL;
}
int Stack:: top () {
    if (empty()) return INF;
    return tail -> key;
}
int Stack:: pop() {
    if (empty()) return INF;
    if (size () == 1) {
        tail = NULL;
        return -INF;
    }
    node * temp = tail;
    tail = tail -> pre;
    tail -> nexT = NULL;
    int ans = temp -> key;
    delete temp;
    return ans;
}
int main () {

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值