//C语言 typedef struct { int front; int back; int maxFront; int maxBack; int max[10001]; int queue[10001]; } MaxQueue; MaxQueue* maxQueueCreate() { MaxQueue* obj = (MaxQueue*)calloc(sizeof(MaxQueue),1); return obj; } int maxQueueMax_value(MaxQueue* obj) { return (obj->maxFront != obj->maxBack)?obj->max[obj->maxFront] :-1; } void maxQueuePush_back(MaxQueue* obj, int value) { while(obj->maxFront != obj->maxBack && obj->max[obj->maxBack-1] < value){ obj->maxBack--; } obj->max[obj->maxBack++]=value; obj->queue[obj->back++]=value; } int maxQueuePop_front(MaxQueue* obj) { if(obj->front != obj->back){ if(obj->queue[obj->front] == obj->max[obj->maxFront]) obj->maxFront++; return obj->queue[obj->front++]; } return -1; } void maxQueueFree(MaxQueue* obj) { free(obj); } /** * Your MaxQueue struct will be instantiated and called as such: * MaxQueue* obj = maxQueueCreate(); * int param_1 = maxQueueMax_value(obj); * maxQueuePush_back(obj, value); * int param_3 = maxQueuePop_front(obj); * maxQueueFree(obj); */