lab_gdb
Gruesome GDB
List< T > Class Template Reference

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"

+ Collaboration diagram for List< T >:

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...
 
ListNodereverse (ListNode *curr, ListNode *prev, int len)
 Helper function to recursively reverse the enitre sequence of linked memory inside a List. More...
 

Private Attributes

ListNodehead
 The head of the List. More...
 
int length
 The length of the current List. More...
 

Detailed Description

template<class T>
class List< T >

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.

Constructor & Destructor Documentation

template<class T >
List< T >::List ( )

Default List constructor.

Creates an empty List.

See also
list_given.cpp
template<class T >
List< T >::List ( const List< T > &  other)

Copy constructor for a List.

Since Lists allocate dynamic memory (i.e., they use "new", we must define the Big Three).

See also
list_given.cpp
Parameters
otherThe list we are copying.
template<class T >
List< T >::~List ( )

Destroys the current List.

This function should ensure that memory does not leak on destruction of a list.

Member Function Documentation

template<class T >
List< T > & List< T >::operator= ( const List< T > &  rhs)

Overloaded assignment operator for Lists.

Part of the Big Three that we must define because the class allocates dynamic memory.

See also
list_given.cpp
Parameters
rhsThe right hand side of the assignment statement.
template<class T >
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.

See also
list_given.cpp
Returns
The size of the current List.
template<class T >
void List< T >::print ( ostream &  os) const

Used to print the list.

Const because it promises not to modify the current List.

See also
list_given.cpp
Parameters
osOutput stream to print the list to (e.g. cout)
template<class T >
bool List< T >::empty ( ) const

Determines if the current List is empty.

Const because it promises not to modify the current List.

See also
list_given.cpp
Returns
Boolean value of whether the current List is empty.
template<class T >
void List< T >::insertFront ( const T &  ndata)

Inserts a new node at the front of the List.

This function SHOULD create a new ListNode.

Parameters
ndataThe data to be inserted.
template<class T >
void List< T >::insertBack ( const T &  ndata)

Inserts a new node at the back of the List.

This function SHOULD create a new ListNode.

Parameters
ndataThe data to be inserted.
template<class T >
void List< T >::reverse ( )

Reverses the current List.

template<class T >
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 >

template<class T >
void List< T >::copy ( const List< T > &  other)
private

Copies the given list into the current list.

See also
list_given.cpp
Parameters
otherThe List to be copied.
template<class T >
void List< T >::clear ( )
private

Destroys all dynamically allocated memory associated with the current List class.

template<class T >
List< T >::ListNode * List< T >::reverse ( ListNode curr,
ListNode prev,
int  len 
)
private

Helper function to recursively reverse the enitre sequence of linked memory inside a List.

Parameters
currA pointer to the current list node we are reversing.
prevA pointer to the node that should come before the current node in the final reversed list.
currThe current node we are reversing
prevThe node that should be placed before the current node in the final reversed list
lenThe length of the remaining list to be reversed

Member Data Documentation

template<class T >
ListNode* List< T >::head
private

The head of the List.

May be NULL if the List is empty.

template<class T >
int List< T >::length
private

The length of the current List.

Do not forget to update it!


The documentation for this class was generated from the following files: