71 reverse(head_, tail_);
110 template <
typename T>
121 template <
typename T>
123 if (splitPoint > length_)
129 ListNode * secondHead = split(head_, splitPoint);
131 int oldLength = length_;
132 if (secondHead == head_) {
140 while (tail_ -> next != NULL)
142 length_ = splitPoint;
147 ret.
head_ = secondHead;
148 ret.
tail_ = secondHead;
149 if (ret.
tail_ != NULL) {
150 while (ret.
tail_->next != NULL)
153 ret.
length_ = oldLength - splitPoint;
170 template <
typename T>
181 template <
typename T>
184 head_ = merge(head_, otherList.
head_);
189 while (tail_->next != NULL)
192 length_ = length_ + otherList.
length_;
195 otherList.
head_ = NULL;
196 otherList.
tail_ = NULL;
211 template <
typename T>
220 template <
typename T>
224 head_ = mergesort(head_, length_);
226 while (tail_->next != NULL)
239 template <
typename T>
ListIterator end() const
Returns a ListIterator one past the end of the List.
Definition: List.hpp:21
void _destroy()
Destroys all dynamically allocated memory associated with the current List class. ...
Definition: List.hpp:40
~List()
Destroys the current List.
Definition: List.hpp:31
ListNode * tail_
The tail of the list.
Definition: List.h:223
ListIterator begin() const
Returns a ListIterator with a position at the beginning of the List.
Definition: List.hpp:12
void mergeWith(List< T > &otherList)
Merges the given sorted list into the current sorted list.
Definition: List.hpp:182
int length_
The length of the current List.
Definition: List.h:228
ListNode * merge(ListNode *first, ListNode *second)
Helper function to merge two sorted and independent sequences of linked memory.
Definition: List.hpp:212
void reverse()
Reverses the current List.
Definition: List.hpp:70
List: This is a templated linked list class (meaning it contains data of templated type T...
Definition: List.h:21
ListNode * mergesort(ListNode *start, int chainLength)
Sorts a chain of linked memory given a start node and a size.
Definition: List.hpp:240
The ListNode class is private to the List class via the principle of encapsulation—the end user does...
Definition: List.h:28
ListNode * head_
The head of the List.
Definition: List.h:218
void insertFront(const T &ndata)
Inserts a new node at the front of the List.
Definition: List.hpp:51
void insertBack(const T &ndata)
Inserts a new node at the back of the List.
Definition: List.hpp:62
List< T > split(int splitPoint)
Splits the given list into two parts by dividing it at the splitPoint.
Definition: List.hpp:122
void sort()
Sorts the current list by applying the Mergesort algorithm.
Definition: List.hpp:221
void reverseNth(int n)
Reverses blocks of size n in the current List.
Definition: List.hpp:97
void waterfall()
Modifies the List using the waterfall algorithm.
Definition: List.hpp:111