循环队列
查看原帖
循环队列
1021055
gdz0214_and_zxb0214楼主2025/1/30 10:46
#include<bits/stdc++.h>
#define il inline
#define int long long
const int N=2e6+10;
class Queue{
    public:
		Queue(){
    		st=ed=0;
    	}
	    il bool empty(){
	        return st==ed;
	    }
	    il bool full(){
	        return (ed+1)%N==st;
	    }
	    il bool push(int x){
	        if(full()) return 0;
	        s[ed]=x;
	        ed=(ed+1)%N;
	        return 1;
	    }
	    il bool pop(){
	        if(empty()) return 0;
	        st=(st+1)%N;
	        return 1;
	    }
	    il int front(){
	        return (empty()?-1:s[st]);
	    }
	    il void clear(){
	        st=ed=0;
	    }
	    il int size(){
	        return (ed-st+N)%N;
	    }
	    il void put() {
	        for(int i=st;i!=ed;i=(i+1)%N) {
	            printf("%lld ",s[i]);
	        }
	        printf("\n");
	    }
    private: 
		int st,ed,s[N];
};
signed main(){
	return 0;
}

求改进T^T

2025/1/30 10:46
加载中...