#pragma once
#ifndef ___LinkedQueue
#define ___LinkedQueue
//LinkedQueue.h : 연결된 큐 클래스
#include "Node_Int.h"
class LinkedQueue {
Node_Int* front; //가장 먼저 삽입된 노드의 포인터
Node_Int* rear; //마지막에 삽입된 노드의 포인터
public:
LinkedQueue() : front(NULL), rear(NULL) {}
~LinkedQueue() { while (!isEmpty()) delete dequeue(); }
bool isEmpty() { return front == NULL; }
//삽입 연산 : 연결된 큐의 맨 뒤에 노드 삽입
void enqueue(Node_Int* p) {
if (isEmpty()) front = rear = p;
else {
rear->setLink(p);
rear = p;
}
}
//삭제 연산 : 연결된 큐의 맨 앞 노드를 삭제
Node_Int* dequeue() {
if (isEmpty()) return NULL;
Node_Int* p = front;
front = front->getLink();
if (front == NULL) rear = NULL;
return p;
}
Node_Int* peek() { return front; }
void display() {
printf("[큐 내용] : ");
for (Node_Int* p = front; p != NULL; p = p->getLink())
p->display();
printf("\n");
}
};
#endif // !___LinkedQueue
'Programming > DS SorceCode' 카테고리의 다른 글
ArrayList.h : 배열을 이용한 리스트 클래스 구현 (0) | 2019.03.23 |
---|---|
StudentQueue.h : 학생정보 큐 클래스 (0) | 2019.03.23 |
Node_Int : 연결된 큐를 위한 int형 클래스 (0) | 2019.03.22 |
LinkedStack.h : 연결된 스택 클래스 구현 (0) | 2019.03.22 |
Node_Student.h : 연결된 스택을 위한 노드 클래스 구현 파일 (0) | 2019.03.22 |