본문 바로가기
자료구조/Queue

[깡구현] QUEUE

by BAYABA 2020. 3. 4.

문제: https://swexpertacademy.com/main/code/problem/problemSolverCodeDetail.do


#define QUEUE_SIZE 1001
 
struct Queue {
	
    //h(head): POP할 때 마다 갱신, t(tail): PUSH할 때 마다 갱신
    int q[QUEUE_SIZE], h = 0, t = 0, sz = 0;
    int front() const {
        return q[h];
    }
    void pop() {
        h = (h + 1) % QUEUE_SIZE;        
        sz--;
    }
    void push(int d) {
        q[t] = d;
        t = (t + 1) % QUEUE_SIZE;        
        sz++;
    }
    int size() const {
        return sz;
    }
    bool empty() const {
    	return (h == t);
    }
    
}Queue;

'자료구조 > Queue' 카테고리의 다른 글

[깡구현] QUEUE_2  (0) 2020.05.16