배열을 이용한 원형 큐 #define QUEUE_CAPACITY 8 int queue_size =0; int tail = -1; int head = 0; int queue[QUEUE_CAPACITY]; void enqueue(int n) { if(queue_size == QUEUE_CAPACITY) return; //full return tail = (tail +1) % QUEUE_CAPACITY; ++queue_size; queue[tail] = n; } int dequeue() { int r; if(queue_size == 0) return; //empty r = queue[head]; head = (head+1) % QUEUE_CAPACITY; --queue_size; return r; }
0 개의 댓글:
댓글 쓰기