-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.cpp
More file actions
48 lines (41 loc) · 792 Bytes
/
queue.cpp
File metadata and controls
48 lines (41 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "queue.h"
Queue::Queue():LinkedList()
{
tail = nullptr;
}
Queue::~Queue(){}
// Queue의 정의에 맞게 데이터를 삽입한다.
void Queue::push(int data)
{
Node* newNode = new Node(data);
if (size_ == 0)
{
head_ = newNode;
tail = newNode;
}
else
{
tail->next_ = newNode;
tail = newNode;
}
size_++;
}
// Queue의 정의에 맞게 데이터를 꺼내고 적절한 메모리를 해제한다.
int Queue::pop()
{
int result = head_->value_;
Node* temp = head_->next_;
delete head_;
head_ = temp;
size_--;
return result;
}
// Queue의 정의에 맞게 다음에 pop 될 값을 미리 본다.
int Queue::peek()
{
return head_->value_;
}
void Queue::operator+=(int data)
{
push(data);
}