zoukankan      html  css  js  c++  java
  • 【leetcode】用化栈为队

    typedef struct {
        int top;
        int bottom;
        int arr[10000];
    } MyQueue;
    
    /** Initialize your data structure here. */
    
    MyQueue* myQueueCreate() {
        MyQueue* obj = (MyQueue*)calloc(1,sizeof(MyQueue));
        obj->top=0;
        obj->bottom=-1;
        return obj;
    }
    
    /** Push element x to the back of queue. */
    void myQueuePush(MyQueue* obj, int x) {
        obj->arr[++obj->bottom]=x;
    }
    
    /** Removes the element from in front of queue and returns that element. */
    int myQueuePop(MyQueue* obj) {
        return obj->arr[obj->top++];
    }
    
    /** Get the front element. */
    int myQueuePeek(MyQueue* obj) {
        return obj->arr[obj->top];
    }
    
    /** Returns whether the queue is empty. */
    bool myQueueEmpty(MyQueue* obj) {
        return obj->top > obj->bottom;
    }
    
    void myQueueFree(MyQueue* obj) {
        free(obj);
    }
  • 相关阅读:
    javaScript
    CSS
    HTML
    折纸 (模拟)
    不等式(数学)
    周期串查询
    大集训模拟赛十一
    大假期集训模拟赛十
    P1631 序列合并
    KMP(烤馍片)算法
  • 原文地址:https://www.cnblogs.com/ganxiang/p/13733718.html
Copyright © 2011-2022 走看看