zoukankan      html  css  js  c++  java
  • 【leetcode】用队列实现栈

    typedef struct {
        int top;
        int q[10000];
    } MyStack;
    
    /** Initialize your data structure here. */
    
    MyStack* myStackCreate() {
        MyStack* obj = (MyStack*)calloc(1,sizeof(MyStack));
        obj->top=-1;
        return obj;
    }
    
    /** Push element x onto stack. */
    void myStackPush(MyStack* obj, int x) {
        obj->q[++obj->top]=x;
    }
    
    /** Removes the element on top of the stack and returns that element. */
    int myStackPop(MyStack* obj) {
        return obj->q[obj->top--];
    }
    
    /** Get the top element. */
    int myStackTop(MyStack* obj) {
        return obj->q[obj->top];
    }
    
    /** Returns whether the stack is empty. */
    bool myStackEmpty(MyStack* obj) {
        return obj->top == -1;
    }
    
    void myStackFree(MyStack* obj) {
        free(obj);
    }
  • 相关阅读:
    RegExp
    svn操作
    前端跨域请求
    UML
    excel 常用设置
    python中 cmp
    python global nonlocal
    python常见异常提示
    table边框和td的width失效
    display_css
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13731947.html
Copyright © 2011-2022 走看看