DoublyIter2.h
3.53 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#pragma once
#ifndef _UN_SORTED_LINKED_LIST_H
#define _UN_SORTED_LINKED_LIST_H
#include"UnSortedLinkedList.h"
template<typename T>
class UnSortedLinkedList;
template<typename T>
struct NodeType2;
template<typename T>
class DoublyIter2 {
friend class UnSortedLinkedList<T>;
private:
const UnSortedLinkedList<T>& m_List;
NodeType2<T>* CurPointer;
public:
DoublyIter2(const UnSortedLinkedList<T>& list) : m_List(list), CurPointer(list.m_pList)
{}
/**
* @brief 현재 노드를 가리키는 포인터가 null인지 아닌지 판단하는 메서드.
* @pre Iterator has been initialized.
* @post None.
* @return nullptr true, otherwise false.
*/
bool NotNull();
/**
* @brief 현재 노드 포인터의 다음 노드가 null인지 아닌지 판단하는 메서드.
* @pre Iterator has been initialized.
* @post None.
* @return nullptr true, otherwise false.
*/
bool NextNotNull();
/**
* @brief 현재 노드 포인터의 이전 노드가 null인지 아닌지 판단하는 메서드.
* @pre Iterator has been initialized.
* @post None.
* @return nullptr true, otherwise false.
*/
bool PrevNotNull();
/**
* @brief Get first data of the list.
* @pre Iterator has been initialized.
* @post Current pointer is moved to the first node.
* @return Return first data of the list.
*/
T First();
/**
* @brief Get next data of the current pointer.
* @pre Iterator has been initialized.
* @post Current pointer is moved to the next node.
* @return Return next data of the list.
*/
T Next();
/**
* @brief Get current data of the list and go to the next node. 현재 노드. 객체반환은 return by value
* @pre Iterator has been initialized.
* @post Current pointer is moved to next node.
* @return Return current data of the list.
*/
NodeType2<T> GetCurrentNode();
/**
* @brief 현재 노드의 data의 주소값을 반환하는 함수
* @pre Iterator has been initialized.
* @post x
* @return Return current data's address
*/
T* GetCurrentPtr();
/**
* @brief 마지막 데이터의 포인터를 받는다.
* @pre Iterator has been initialized.
* @post x
* @return Return last data of the list.
*/
T Last();
/**
* @brief Curpointer의 이전 노드로 간다
* @pre Iterator has been initialized.
* @post 이전 노드로 포인터가 이동한다
* @return Return Prev data of the list.
*/
T Prev();
};
// 현재 원소가 null인지 검사
template <typename T>
bool DoublyIter2<T>::NotNull() {
if (CurPointer == NULL) {
return false;
}
else return true;
}
// 다음 원소가 null인지 검사
template <typename T>
bool DoublyIter2<T>::NextNotNull() {
if (CurPointer->next == NULL) {
return false;
}
else
return true;
}
template<typename T>
bool DoublyIter2<T>::PrevNotNull()
{
if (CurPointer->Prev == NULL)
return false;
else
return true;
}
// 첫 번째 node
template <typename T>
T DoublyIter2<T>::First() {
if (!m_List.IsEmpty()) {
CurPointer = m_List.m_pFirst;
return CurPointer->data;
}
}
// 다음 node로 이동 후 item을 return.
template <typename T>
T DoublyIter2<T>::Next() {
T output = CurPointer->data;
if (NotNull()) {
CurPointer = CurPointer->next;
}
return output;
}
template<typename T>
T DoublyIter2<T>::Last()
{
if (!m_List.IsEmpty()) {
CurPointer = m_List.m_pLast;
return CurPointer->data;
}
}
template<typename T>
T DoublyIter2<T>::Prev()
{
T output = CurPointer->data;
if (NotNull()) {
CurPointer = CurPointer->pre;
}
return output;
}
// 현재 node를 return
template <typename T>
NodeType2<T> DoublyIter2<T>::GetCurrentNode() {
if (CurPointer != NULL) {
return *CurPointer;
}
}
template<typename T>
T* DoublyIter2<T>::GetCurrentPtr()
{
if (CurPointer != NULL)
{
return &(CurPointer->data);
}
}
#endif // !_DOUBLY_ITER2_H