MP3
Linked Lists
List.hpp
1 
11 template <typename T>
13  // @TODO: graded in MP3.1
14  return List<T>::ListIterator(nullptr);
15 }
16 
20 template <typename T>
22  // @TODO: graded in MP3.1
23  return List<T>::ListIterator(nullptr);
24 }
25 
30 template <typename T>
33 }
34 
39 template <typename T>
42 }
43 
50 template <typename T>
51 void List<T>::insertFront(T const & ndata) {
53 }
54 
61 template <typename T>
62 void List<T>::insertBack(const T & ndata) {
64 }
65 
69 template <typename T>
71  reverse(head_, tail_);
72 }
73 
85 template <typename T>
86 void List<T>::reverse(ListNode *& startPoint, ListNode *& endPoint) {
88 }
89 
96 template <typename T>
97 void List<T>::reverseNth(int n) {
99 }
100 
110 template <typename T>
113 }
114 
121 template <typename T>
122 List<T> List<T>::split(int splitPoint) {
123  if (splitPoint > length_)
124  return List<T>();
125 
126  if (splitPoint < 0)
127  splitPoint = 0;
128 
129  ListNode * secondHead = split(head_, splitPoint);
130 
131  int oldLength = length_;
132  if (secondHead == head_) {
133  // current list is going to be empty
134  head_ = NULL;
135  tail_ = NULL;
136  length_ = 0;
137  } else {
138  // set up current list
139  tail_ = head_;
140  while (tail_ -> next != NULL)
141  tail_ = tail_->next;
142  length_ = splitPoint;
143  }
144 
145  // set up the returned list
146  List<T> ret;
147  ret.head_ = secondHead;
148  ret.tail_ = secondHead;
149  if (ret.tail_ != NULL) {
150  while (ret.tail_->next != NULL)
151  ret.tail_ = ret.tail_->next;
152  }
153  ret.length_ = oldLength - splitPoint;
154  return ret;
155 }
156 
170 template <typename T>
171 typename List<T>::ListNode * List<T>::split(ListNode * start, int splitPoint) {
173  return NULL;
174 }
175 
181 template <typename T>
182 void List<T>::mergeWith(List<T> & otherList) {
183  // set up the current list
184  head_ = merge(head_, otherList.head_);
185  tail_ = head_;
186 
187  // make sure there is a node in the new list
188  if (tail_ != NULL) {
189  while (tail_->next != NULL)
190  tail_ = tail_->next;
191  }
192  length_ = length_ + otherList.length_;
193 
194  // empty out the parameter list
195  otherList.head_ = NULL;
196  otherList.tail_ = NULL;
197  otherList.length_ = 0;
198 }
199 
211 template <typename T>
212 typename List<T>::ListNode * List<T>::merge(ListNode * first, ListNode* second) {
214  return NULL;
215 }
216 
220 template <typename T>
222  if (empty())
223  return;
224  head_ = mergesort(head_, length_);
225  tail_ = head_;
226  while (tail_->next != NULL)
227  tail_ = tail_->next;
228 }
229 
239 template <typename T>
240 typename List<T>::ListNode* List<T>::mergesort(ListNode * start, int chainLength) {
242  return NULL;
243 }
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