연결 리스트 - 큐 본문

Programming/기타 언어들

연결 리스트 - 큐

쩡호 2017. 4. 23. 18:42

Queue.h 파일


#include<iostream>

using namespace std;


class Node {

Node* link;

int data;

public:

Node(int val = 0) :data(val), link(NULL) {}

Node* getLink() { return link; }

void setLink(Node* next) { link = next; }

void display() { cout << "<" << data << ">"; }

};





LinkedQueue.h 파일


#include "Queue.h"

using namespace std;


class LinkedQueue {

Node* front;

Node* rear;

public:

LinkedQueue() :front(NULL), rear(NULL) {}

~LinkedQueue() { 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() {

cout << "[큐 내용] : ";

for (Node* p = front; p != NULL; p = p->getLink())

p->display();

cout << endl;

}

};



'Programming > 기타 언어들' 카테고리의 다른 글

단축키  (0) 2017.05.24
언리얼의 데이터 유형  (0) 2017.05.18
연결 리스트 - 스택  (0) 2017.04.23
C++ rand() 함수  (0) 2017.04.23
c++ 소수점 아래 고정 하기  (0) 2017.04.15
Comments