Skip to content

Commit

Permalink
[Queue] Fix error code
Browse files Browse the repository at this point in the history
  • Loading branch information
deunlee committed May 29, 2020
1 parent de97791 commit 2853655
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 8 additions & 3 deletions Queue/Queue.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef __DEUN_QUEUE_CPP__
#define __DEUN_QUEUE_CPP__

#include "Queue.h"

namespace Deun {
Expand All @@ -8,7 +11,7 @@ namespace Deun {

if (!elements) {
this->size = 0;
throw QueueError::QUEUE_ALLOCATION_FAILED;
throw QueueError::MEMORY_ALLOCATION_FAILED;
}
}

Expand Down Expand Up @@ -48,7 +51,7 @@ namespace Deun {

int Queue::dequeue() {
if (isEmpty()) {
throw QueueError::QUEUE_IS_EMPTY;
throw QueueError::ELEMENT_NOT_FOUND;
}

count--;
Expand All @@ -59,9 +62,11 @@ namespace Deun {

int Queue::peek() {
if (isEmpty()) {
throw QueueError::QUEUE_IS_EMPTY;
throw QueueError::ELEMENT_NOT_FOUND;
}

return elements[front];
}
}

#endif
14 changes: 7 additions & 7 deletions Queue/Queue.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef __DEUN_QUEUE__
#define __DEUN_QUEUE__
#ifndef __DEUN_QUEUE_H__
#define __DEUN_QUEUE_H__

#include <new>

namespace Deun {
enum class QueueError {
QUEUE_ALLOCATION_FAILED,
QUEUE_IS_EMPTY,
MEMORY_ALLOCATION_FAILED = 1000,
ELEMENT_NOT_FOUND,
};

// 배열 기반 원형 큐
Expand All @@ -22,7 +22,7 @@ namespace Deun {
unsigned int rear; // 원소를 삽입할 자리

public:
Queue(unsigned int size = 100);
Queue(unsigned int size = 1000);
~Queue();

bool isEmpty();
Expand All @@ -31,9 +31,9 @@ namespace Deun {
unsigned int getSize(); // 전체 크기 반환
unsigned int getCount(); // 채워진 원소의 개수 반환

bool enqueue(int element); // 맨 뒤에 원소 삽입 (성공 = true, 실패 = false)
bool enqueue(int element); // 맨 뒤에 원소 삽입 (성공 = true, 실패 = false)
int dequeue(); // 맨 앞 원소 반환 및 삭제 (실패 = throw)
int peek(); // 맨 앞 원소 반환 (실패 = throw)
int peek(); // 맨 앞 원소 반환 (실패 = throw)
};
}

Expand Down

0 comments on commit 2853655

Please sign in to comment.