-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedList.h
66 lines (54 loc) · 1.64 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
#pragma once
#include "adts/list.h"
// This file declares two classes: a LinkedListNode class (which represents a
// single node in a linked list) and a LinkedList class (which represents a
// full linked list as an implementation of the List ADT).
/**
* This class represents a single node in a linked list. It contains
* one list element as well as pointers to the nodes which follow it
* (or NULL when those nodes don't exist).
* @tparam T The type of data stored in the list.
*/
template <typename T> class LinkedListNode {
public:
/**
* Constructs a new node.
* @param val The value to store in the node.
* @param next An optional pointer to the following node.
* If unspecified next should be set to nullptr.
*/
LinkedListNode<T>(T val, LinkedListNode<T>* next);
// public data members:
T value;
LinkedListNode<T>* next;
};
/**
* This class implements this list ADT as a linked list.
* @tparam T The type of data stored in the list.
*/
template <typename T> class LinkedList : public List<T> {
public:
LinkedList();
~LinkedList();
/**
* Confirms that there are this->size elements in the list.
* @throws runtime_error if the invariant does not hold.
*/
void checkInvariants();
// See list.h for comments on these methods:
int getSize();
bool isEmpty();
T getFirst();
T getLast();
T get(int index);
void insertFirst(T value);
void insertLast(T value);
T removeFirst();
T removeLast();
void reverseIt();
private:
LinkedListNode<T>* head;
LinkedListNode<T>* tail;
int size;
};
#include "linkedList-inl.h"