MP3
Linked Lists
List.h
1 
5 #pragma once
6 #include <iterator>
7 #include <iostream>
8 #include <algorithm>
9 
10 using namespace std;
11 
20 template <class T>
21 class List {
22  private:
28  class ListNode {
29  public:
35  ListNode();
36 
42  ListNode(const T & ndata);
43 
49 
55 
60  const T data;
61  };
62 
63  public:
69  List();
70 
79  List(const List<T>& other);
80 
89  List<T>& operator=(const List<T>& rhs);
90 
99  int size() const;
100 
108  void print(ostream& os) const;
109 
117  bool empty() const;
118 
123  ~List();
124 
131  void insertFront(const T& ndata);
132 
139  void insertBack(const T& ndata);
140 
144  void reverse();
145 
153  void reverseNth(int n);
154 
165  void waterfall();
166 
174  List<T> split(int splitPoint);
175 
181  void mergeWith(List<T>& otherList);
182 
186  void sort();
187 
188  // ListIterator is an inner-class of List, defined in a separate
189  // file:
190  #include "List-ListIterator.hpp"
191 
196  ListIterator begin() const;
197 
201  ListIterator end() const;
202 
203  // Iterator constructor
204  template <class Iter>
205  List(const Iter& start, const Iter& end);
206 
207  private:
208  /*
209  * Private member variables.
210  *
211  * You must use these as specified in the spec and may not rename them.
212  * You may add more if you need them.
213  */
214 
219 
224 
228  int length_;
229 
230  /*
231  * Private helper functions.
232  *
233  * You must use these as specified in the spec and may not rename them.
234  * You may place more here as you need them.
235  */
236 
242  void _copy(const List<T>& other); // implemented in List-given.hpp
243 
248  void _destroy();
249 
262  void reverse(ListNode*& startPoint, ListNode*& endPoint);
263 
277  ListNode* split(ListNode* start, int splitPoint);
278 
290  ListNode* merge(ListNode* first, ListNode* second);
291 
301  ListNode* mergesort(ListNode* start, int chainLength);
302 };
303 
304 // needed for template instantiation
305 #include "List.hpp"
306 
307 // this includes all of the functions that are given to you
308 // (i.e., the ones that you do not need to implement)
309 #include "List-given.hpp"
ListNode * tail_
The tail of the list.
Definition: List.h:223
STL namespace.
int length_
The length of the current List.
Definition: List.h:228
T end(T...args)
T reverse(T...args)
const T data
The data contained in this node.
Definition: List.h:60
List: This is a templated linked list class (meaning it contains data of templated type T...
Definition: List.h:21
Definition: List-ListIterator.hpp:2
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
T begin(T...args)
ListNode * next
A pointer to the next node in the list.
Definition: List.h:48
T sort(T...args)
ListNode * prev
A pointer to the previous node in the list.
Definition: List.h:54
STL class.
T merge(T...args)