-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinked_List.cpp
86 lines (71 loc) · 1.95 KB
/
Linked_List.cpp
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
#include<iostream>
using namespace std;
template<class T>
class List
{
public:
//Class declarations.
class Iterator;
class ConstIterator;
//Constructors and Destructors.
List() : head(NULL), tail(NULL), size(0) {} //Constructor
~List(); //Destructor
//Methods
Iterator<T> begin();
Iterator<T> end();
void insert(const T& data);
void insert(const T& data, const Iterator<T>& iterator);
void remove(const Iterator<T>& iterator);
int getSize() const;
Iterator<T> find();
void sort();
private:
class Node<T>;
Node<T>* head;
Node<T>* tail;
int size;
};
template<class T>
class List<class T>::Iterator
{
public:
Iterator(); //Constructor
~Iterator(); //Destructor
T& operator ++ ();
T operator ++ (int);
T& operator -- ();
T operator -- (int);
bool operator == (const Iterator<T>& iterator) const;
bool operator != (const Iterator<T>& iterator) const;
T& operator * ();
private:
List<T>* list;
Node<T>* node;
};
template<class T>
class List<class T>::ConstIterator
{
public:
ConstIterator(); //Constructor
~ConstIterator(); //Destructor
T& operator ++ ();
T operator ++ (int);
T& operator -- ();
T operator -- (int);
bool operator == (const ConstIterator<T>& iterator) const;
bool operator != (const ConstIterator<T>& iterator) const;
T& operator * ();
private:
const List<T> * list;
const Node<T> * node;
};
template<class T>
class List<class T>::Node
{
public:
Node(const T& _data, const Node* _next = NULL) : data(_data), next(_next) {} //Constructor
~Node(); //Destructor
private:
T data;
Node* next;
};