In this sub-project, you will implement two classes:
A doubly linked list with a sentinel and three nodes is shown in Figure 1. The empty doubly linked list with a sentinel is shown in Figure 2, the node marked S being the sentinel node.
Figure 1. A doubly linked list with a sentinel and three nodes.
Figure 2. An empty doubly linked list with a sentinel.
Sorted_double_sentinel_list |
---|
- list_head:Double_node - list_tail:Double_node - list_size:Integer |
+ create():Sorted_double_sentinel_list + create( in dsl:Sorted_double_sentinel_list ):Sorted_double_sentinel_list + size():Integer + empty():Boolean + front():Type + back():Type + head():Double_node + tail():Double_node + count( in obj:Type ):Integer + swap( inout list:Sorted_double_sentinel_list ) + =( in rhs:Sorted_double_sentinel_list ):Sorted_double_sentinel_list + insert( in obj:Type ) + pop_front():Type + pop_back():Type + erase( in obj:Type ):Integer + destroy() |
This class stores a finite list of n (zero or more) linearly ordered elements in that order stored in doubly linked nodes. If there are zero elements in the list, the list is said to be empty. Each element is stored in an instance of the Double_node<Type> class. At all times, the head and tail pointers point to head and tail sentinel nodes, respectively. If the list is empty, the tail pointer points to the tail sentinel node and the next pointer the tail sentinel is assigned nullptr while the previous pointer of the tail sentinel is assigned the address of the head sentinel. Otherwise, the next pointer of the head sentinel points to the first node, the next pointer of the ith node (1 ≤ i < n) points to the (i + 1)st node, the next pointer of the nth is assigned to the address of the tail sentinel, the previous pointer of the ith node (2 ≤ i ≤ n) points to the (i − 1)st node, and the previous pointer of the first node points to the sentinel.
The three member variables are:
Sorted_double_sentinel_list()
The constructor creates two instances of a Double_node<Type> (called the sentinels). The head and tail pointers are set to point to one of the sentinels, each. The values stored in these nodes is not important, you can use the default value or whatever values you want. The previous and next pointers of the head sentinel should be nullptr and the address of the tail sentinel, respectively. The previous and next pointers of the tail sentinel should be address of the head sentinel and nullptr, respectively. The node count is set to 0. (O(1))
The destructor must delete each of the nodes in the list including the sentinels. (O(n))
The copy constructor must create a new doubly linked list with a copy of all of the nodes within the linked list with the elements stored in the same order. Once a copy is made, any change to the original linked list must not affect the copy. (O(n) and note that using insert will result in an O(n2) run-time)
This class has seven accessors:
This class has seven mutators: