-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortedListClass.h
More file actions
83 lines (79 loc) · 4.08 KB
/
SortedListClass.h
File metadata and controls
83 lines (79 loc) · 4.08 KB
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
78
79
80
81
#ifndef _SORTEDLISTCLASS_H_
#define _SORTEDLISTCLASS_H_
#include "LinkedNodeClass.h"
//The sorted list class does not store any data directly. Instead,
//it contains a collection of LinkedNodeClass objects, each of which
//contains one element.
template < class T >
class SortedListClass
{
private:
LinkedNodeClass< T > *head; //Points to the first node in a list, or NULL
//if list is empty.
LinkedNodeClass< T > *tail; //Points to the last node in a list, or NULL
//if list is empty.
public:
//Default Constructor. Will properly initialize a list to
//be an empty list, to which values can be added.
SortedListClass();
//Copy constructor. Will make a complete (deep) copy of the list, such
//that one can be changed without affecting the other.
SortedListClass(const SortedListClass< T > &rhs);
//Overloaded assignment operator. Will make a complete (deep) copy
//of the list, such that one can be changed without affecting
//the other. void operator=(const SortedListClass< T > &rhs);
//Clears the list to an empty state without resulting in any
//memory leaks.
void clear();
//Allows the user to insert a value into the list. Since this
//is a sorted list, there is no need to specify where in the list
//to insert the element. It will insert it in the appropriate
//location based on the value being inserted. If the node value
//being inserted is found to be "equal to" one or more node values
//already in the list, the newly inserted node will be placed AFTER
//the previously inserted nodes.
void insertValue(const T &valToInsert //The value to insert into the list
);
//Prints the contents of the list from head to tail to the screen.
//Begins with a line reading "Forward List Contents Follow:", then
//prints one list element per line, indented two spaces, then prints
//the line "End Of List Contents" to indicate the end of the list.
void printForward() const;
//Prints the contents of the list from tail to head to the screen.
//Begins with a line reading "Backward List Contents Follow:", then
//prints one list element per line, indented two spaces, then prints
//the line "End Of List Contents" to indicate the end of the list.
void printBackward() const;
//Removes the front item from the list and returns the value that
//was contained in it via the reference parameter. If the list
//was empty, the function returns false to indicate failure, and
//the contents of the reference parameter upon return is undefined.
//If the list was not empty and the first item was successfully
//removed, true is returned, and the reference parameter will
//be set to the item that was removed.
bool removeFront(T &theVal);
//Removes the last item from the list and returns the value that
//was contained in it via the reference parameter. If the list
//was empty, the function returns false to indicate failure, and
//the contents of the reference parameter upon return is undefined.
//If the list was not empty and the last item was successfully
//removed, true is returned, and the reference parameter will
//be set to the item that was removed.
bool removeLast(T &theVal);
//Returns the number of nodes contained in the list.
int getNumElems() const;
//Provides the value stored in the node at index provided in the
//0-based "index" parameter. If the index is out of range, then outVal
//remains unchanged and false is returned. Otherwise, the function
//returns true, and the reference parameter outVal will contain
//a copy of the value at that location.
bool getElemAtIndex(const int index, T &outVal);
//Destructor, which will free up all dynamic memory associated
//with this list when the list is destroyed (i.e when a statically
//allocated list goes out of scope or a dynamically allocated list
//is deleted).
~SortedListClass();
};
#include "SortedListClass.inl"
#endif