-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.h
116 lines (88 loc) · 1.62 KB
/
LinkedList.h
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
/*
* LinkedList.h
*
* 작성자: Jungdy
* 작성일자: 2017. 12. 28
* 주제명: 직원 명부 프로그램
*
*/
#ifndef _LINKEDLIST_H
#define _LINKEDLIST_H
#include <iostream>
using namespace std;
template <typename T>
class LinkedList{
private:
Node<T>* first;
Node<T>* current;
public:
LinkedList();
~LinkedList();
void push_back(T data);
T pop();
Node<T>* peak() const;
Node<T>* atFirst() const;
bool isEmpty() const;
};
template <typename T>
LinkedList<T>::LinkedList(){
this->first = NULL;
this->current = NULL;
}
template <typename T>
LinkedList<T>::~LinkedList(){
while (current != NULL)
{
pop();
} // end of while
}
template <typename T>
void LinkedList<T>::push_back(T data){
Node<Emp>* createNode = new Node<Emp>();
createNode->setPrev(NULL);
createNode->setData(data);
createNode->setNext(NULL);
if ( current == NULL ){
current = createNode;
first = createNode;
}
else
{
createNode->setPrev(current);
current->setNext( createNode );
current = current->getNext();
} // end of if
}
template <typename T>
T LinkedList<T>::pop(){
if ( current != NULL ){
Node<T>* pNode = current;
T data = current->getData();
if ( current->getPrev() == NULL ){
current = NULL;
first = NULL;
}
else{
current = current->getPrev();
current->setNext(NULL);
}
delete[] pNode;
return data;
}
}
template <typename T>
Node<T>* LinkedList<T>::peak() const{
return current;
}
template <typename T>
Node<T>* LinkedList<T>::atFirst() const{
return first;
}
template <typename T>
bool LinkedList<T>::isEmpty() const{
if ( first != NULL ){
return false;
}
return true;
}
#endif