-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.h
executable file
·77 lines (64 loc) · 1.35 KB
/
list.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
// Ryan Wiener, Porter Haet, 2/16/17
#ifndef list_h
#define list_h
#include <string>
using namespace std;
// nodes are used by the list class
template<typename T>
class node
{
private:
T data;
node<T> *next;
public:
node(T& data, node<T>* n=NULL);
T getData();
T* getDataPointer();
node<T>* getNext();
void setNext(node<T>* n);
};
// valueNode is used in map to manage collisions
template<typename K, typename V>
struct valueNode {
K key;
V value;
valueNode* next;
valueNode(K& initKey, V& initValue, valueNode<K, V> *initNext);
};
// map is used to improve performace by keeping track
// of each value in the list and its location in memory
template<typename K, typename V>
class map
{
private:
static const int MAX_SIZE = 500;
valueNode<K, V>* keys[MAX_SIZE];
public:
map();
void set(K k, V v);
V get(K k);
};
// uses a map to make finding operations O(1)
template<typename S>
class list
{
private:
node<S> *headptr, *iter;
map<S, node<S>* > hashMap;
int len;
public:
list();
int length();
void pushfront(S& data);
S get(int index);
// returns a pointer to the data equal to the argument
S* getDataPointer(S& data);
// Allows for the traversal of the linked list
void startIterating();
S getCurrent();
S* getCurrentPointer();
void iterate();
bool hasNext();
};
#include "list.cpp"
#endif // list_h