lab_gdb
Gruesome GDB
|
List: This is a templated linked list class (meaning it contains data of templated type T, which is a placeholder for a type). More...
#include "list.h"
Classes | |
class | ListNode |
The ListNode class is private to the List class via the principle of encapsulation—the end user does not need to know our node-based implementation details. More... | |
Public Member Functions | |
List () | |
Default List constructor. More... | |
List (const List< T > &other) | |
Copy constructor for a List. More... | |
List< T > & | operator= (const List< T > &rhs) |
Overloaded assignment operator for Lists. More... | |
int | size () const |
Gets the size of the List. More... | |
void | print (ostream &os) const |
Used to print the list. More... | |
bool | empty () const |
Determines if the current List is empty. More... | |
~List () | |
Destroys the current List. More... | |
void | insertFront (const T &ndata) |
Inserts a new node at the front of the List. More... | |
void | insertBack (const T &ndata) |
Inserts a new node at the back of the List. More... | |
void | reverse () |
Reverses the current List. More... | |
void | shuffle () |
Shuffles the current list by applying a perfect shuffle once. More... | |
Private Member Functions | |
void | copy (const List< T > &other) |
Copies the given list into the current list. More... | |
void | clear () |
Destroys all dynamically allocated memory associated with the current List class. More... | |
ListNode * | reverse (ListNode *curr, ListNode *prev, int len) |
Helper function to recursively reverse the enitre sequence of linked memory inside a List. More... | |
Private Attributes | |
ListNode * | head |
The head of the List. More... | |
int | length |
The length of the current List. More... | |
List: This is a templated linked list class (meaning it contains data of templated type T, which is a placeholder for a type).
You should NOT remove anything from this class definition. You should NOT modify this file.
Copy constructor for a List.
Since Lists allocate dynamic memory (i.e., they use "new", we must define the Big Three).
other | The list we are copying. |
Destroys the current List.
This function should ensure that memory does not leak on destruction of a list.
Overloaded assignment operator for Lists.
Part of the Big Three that we must define because the class allocates dynamic memory.
rhs | The right hand side of the assignment statement. |
int List< T >::size | ( | ) | const |
Gets the size of the List.
Defined as a const function because it promises not to modify the current List in any way.
void List< T >::print | ( | ostream & | os | ) | const |
Used to print the list.
Const because it promises not to modify the current List.
os | Output stream to print the list to (e.g. cout) |
bool List< T >::empty | ( | ) | const |
Determines if the current List is empty.
Const because it promises not to modify the current List.
void List< T >::insertFront | ( | const T & | ndata | ) |
void List< T >::insertBack | ( | const T & | ndata | ) |
void List< T >::shuffle | ( | ) |
Shuffles the current list by applying a perfect shuffle once.
This entails splitting the list in half, then interleaving the two halves. For example: start : < 1, 2, 3, 4, 5 > split : < 1, 2, 3 > < 4, 5 > final : < 1, 4, 2, 5, 3 >
Copies the given list into the current list.
other | The List to be copied. |
|
private |
Destroys all dynamically allocated memory associated with the current List class.
|
private |
Helper function to recursively reverse the enitre sequence of linked memory inside a List.
curr | A pointer to the current list node we are reversing. |
prev | A pointer to the node that should come before the current node in the final reversed list. |
curr | The current node we are reversing |
prev | The node that should be placed before the current node in the final reversed list |
len | The length of the remaining list to be reversed |
|
private |
The length of the current List.
Do not forget to update it!