#include <stdio.h>
#include <string.h>
#include <stdlib.h>

class Queue {
private:
	int queue[5];
	int head, rear;
	int size;
	
public:
	Queue() {
		size = 5;
		for (int i=0; i<size; i++) queue[i] = 0;
		head = -1;
		rear = 0;
	}
	
	void enqueue(int elem) {
		if (rear == size) {
			printf("큐가 다 찼습니다.\n");
			return;
		}
		if (head == -1) head = 0;
		queue[rear] = elem;
		rear++;
	}
	
	void dequeue() {
		if (head == -1 || head == rear) {
			printf("큐가 비어있습니다.\n");
			return;
		}
		printf("dequeue 결과: %d\n", queue[head]);
		head++;
	}
	
	void display() { // 숙제 
		
	}
};

int main() {
	Queue q1;
	q1.enqueue(1);
	q1.enqueue(2);
	q1.display();
	q1.dequeue();
	q1.display();
	
	return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: