-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoublyLinkedList.h
54 lines (40 loc) · 1.3 KB
/
DoublyLinkedList.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
#ifndef DOUBLYLINKEDLIST_H
#define DOUBLYLINKEDLIST_H
#include <cstdlib>
#include <iostream>
template<class T>
struct NodeType {
T data;
NodeType<T>* next;
NodeType<T>* back;
}; // node
template<class T>
class DoublyLinkedList {
public:
/* Constructor for the doubly linked list. */
DoublyLinkedList();
/* Destructor for the doubly linked list. */
~DoublyLinkedList();
/* Inserts an item into its sorted position within the list. */
void insertItem(T item);
/* Deletes an item from the list if it exists, otherwise prints the list
as it currently exists. */
void deleteItem(T item);
/* Returns the length of the list as an instance variable. */
int lengthIs() const;
/* Prints the list as it currently exists in ascending order. */
void print();
/* Prints the list as it currently exists in descending order. */
void printReverse();
/* Provided a range from the user, any items that exist within that range will
be deleted from the list. */
void deleteSubsection(T lower, T upper);
/* Returns the statistical mode of the list. */
void mode();
/* Swaps pairs of nodes, i.e. 1 and 2, 3 and 4, etc... */
void swapAlternate();
private:
/* Head of the doubly linked list. */
NodeType<T>* head;
}; // dll
#endif