forked from Karlina-Bytes/HashTable_Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList.h
71 lines (56 loc) · 1.94 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
67
68
69
70
71
//*****************************************************************
// LinkedList.h
// HashTable
//
// Created by Karlina Beringer on June 16, 2014.
//
// This header file contains the Linked List class declaration.
// Hash Table array elements consist of Linked List objects.
//*****************************************************************
#ifndef LinkedList_h
#define LinkedList_h
#include <iostream>
#include <string>
using namespace std;
//*****************************************************************
// List items are keys with pointers to the next item.
//*****************************************************************
struct Item
{
string key;
Item * next;
};
//*****************************************************************
// Linked lists store a variable number of items.
//*****************************************************************
class LinkedList
{
private:
// Head is a reference to a list of data nodes.
Item * head;
// Length is the number of data nodes.
int length;
public:
// Constructs the empty linked list object.
// Creates the head node and sets length to zero.
LinkedList();
// Inserts an item at the end of the list.
void insertItem( Item * newItem );
// Removes an item from the list by item key.
// Returns true if the operation is successful.
bool removeItem( string itemKey );
// Searches for an item by its key.
// Returns a reference to first match.
// Returns a NULL pointer if no match is found.
Item * getItem( string itemKey );
// Displays list contents to the console window.
void printList();
// Returns the length of the list.
int getLength();
// De-allocates list memory when the program terminates.
~LinkedList();
};
#endif
//*****************************************************************
// End of File
//*****************************************************************