Queue
← 기록 / Container

Queue

Queue 관련 기록.

이 글의 목차
  1. Circular Queue
  2. Time Complexity

Circular Queue

constexpr int MAX_QUEUE = 1'000'000;
template<typename T>
struct Queue {
    T q[MAX_QUEUE];
    int qf, qr; // queue front, rear
    void init() {
        qf = qr = 0;
    }
    bool isEmpty() {
        return qf == qr;
    }
    void insert(T v) {
        q[qr++] = v;
        qr %= MAX_QUEUE;
    }
    T pop() {
        T res = q[qf++];
        qf %= MAX_QUEUE;
        return res;
    }
};

Time Complexity

  • Insert: O(1)O(1)
  • Pop: O(1)O(1)
AI로 읽기 · Markdown

로그인 없이 읽는 Markdown 원문.

Markdown 열기 ↗
curl -fsSL 'https://www.readiz.com/notes/data-structure/container/queue/index.md'

서비스 열기

열기 방식을 선택해 주세요.

로그인이 필요하거나 창 안에서 열리지 않는 서비스는 현재 탭에서 열어 주세요.