StudentQueue.h : 학생정보 큐 클래스
#pragma once
#ifndef ___StudentQueue
#define ___StudentQueue
#include "Node_Student.h"
//StudentQueue.h : 학생정보 큐 클래스
class StudentQueue {
Node* front; //가장 먼저 삽입된 노드의 포인터
Node* rear; //마지막에 삽입된 노드의 포인터
public:
StudentQueue() : front(NULL), rear(NULL) {}
~StudentQueue() { while (!isEmpty()) delete dequeue(); }
bool isEmpty() { return front == NULL; }
//삽입 연산 : 연결된 큐의 맨 뒤에 노드 삽입
void enqueue(Node* p) {
if (isEmpty()) front = rear = p;
else {
rear->setLink(p);
rear = p;
}
}
//삭제 연산 : 연결된 큐의 맨 앞 노드를 삭제
Node* dequeue() {
if (isEmpty()) return NULL;
Node* p = front;
front = front->getLink();
if (front == NULL) rear = NULL;
return p;
}
Node* peek() { return front; }
void display() {
printf("[전체 학생 정보]\n");
for (Node* p = front; p != NULL; p = p->getLink())
p->display();
printf("\n");
}
};
#endif // !___StudentQueue