티스토리 뷰
큐의 연산 - 큐의 생성
변수 rear의 초기값은 큐의 공백 상태를 나타내는 ‘–1’로 시작함
1 2 3 4 5 | #define QUEUE_SIZE 5 typedef int element; element queue[QUEUE_SIZE]; int front = -1; int rear = -1; | cs |
큐의 연산 - 큐의 초기 상태
front ↓ | rear ↓ | |||||
[0] | [1] | [2] | [3] | [4] | ||
queue | 100 | 200 | 300 |
큐의 연산 - 큐의 삽입 연산
삽입 연산이 발생하면 rear 변수만 오른쪽으로 이동하고, 삭제 연산이 발생하면 front 변수만 오른쪽으로 이동함
1 2 3 4 5 6 7 8 9 | void Add_q(int *rear, element item) { if (*rear == QUEUE_SIZE-1) { printf(“Queue is full !!”); return; } queue[++(*rear)] = item; return; } | cs |


큐의 연산 - 큐의 삭제 연산
삭제 연산의 수행 결과로 삭제된 원소를 Delete_q 연산자의 호출 프로그램에게 반환해 줌
1 2 3 4 5 6 7 8 | element Delete_q(int *front, int rear) { if (*front == rear) { printf("Queue is empty\n"); return; } return ( queue[++(*front)] ); } | cs |
큐의 연산 - 큐의 삽입 / 삭제 연산

