-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDLinkedList.hpp
35 lines (31 loc) · 1.2 KB
/
DLinkedList.hpp
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
#ifndef DLINKEDLIST_H
#define DLINKEDLIST_H
typedef char Elem; // Element type of the doubly linked list
// Class of a doubly linked list node
class DNode{
private:
Elem elem;
DNode* prev;
DNode* next;
friend class DLinkedList;
};
// Class of a doubly linked list
class DLinkedList{
public:
DLinkedList(); // Constructor
~DLinkedList(); // Destructor
bool isEmpty() const; // Check if the doubly linked list is empty
const Elem& front() const; // Return the first element of the doubly linked list
const Elem& back() const; // Return the last element of the doubly linked list
void addFront(const Elem& element); // Add a new element at the front of the doubly linked list
void addBack(const Elem& element); // Add a new element at the back of the doubly linked list
void removeFront(); // Remove the first element from the front of the doubly linked list
void removeBack(); // Remove the last element from the back of the doubly linked list
private:
DNode* header;
DNode* trailer;
protected:
void add(DNode* refNode, const Elem& element); // Insert a new node before the reference node
void remove (DNode* refNode); // Remove the reference node
};
#endif