Here will be displayed some generic code I wrote mostly while attending Full Sail University, but may also include code written during my career after graduating.

 

A Generic Templated Singly Linked List in C++

// DTS 1004
// Aaron Schie 1360283

#ifndef _SLLIST
#define _SLLIST

#include <iostream>
using namespace std;

template <typename Type> class SLLIter;

template <typename Type>
class SLList
{
	struct Node
	{
		Type element;
		Node* next;
		Node(Type const &data, Node * n): element(data),next(n){}
	};
	Node* head;
	unsigned int count;

public:
	///////////////////////////////////////////////////////////////////////////////
	// Function : Constructor
	// Notes : constructs an empty list
	///////////////////////////////////////////////////////////////////////////////
	SLList(): head(0),count(0){}

	///////////////////////////////////////////////////////////////////////////////
	// Function : Destructor
	// Notes : Destroys the list
	///////////////////////////////////////////////////////////////////////////////
	~SLList();

	///////////////////////////////////////////////////////////////////////////////
	// Function : Assignment Operator
	///////////////////////////////////////////////////////////////////////////////
	SLList<Type>& operator=(const SLList<Type>& that);

	///////////////////////////////////////////////////////////////////////////////
	// Function : Copy Constructor
	///////////////////////////////////////////////////////////////////////////////
	SLList(const SLList<Type>& that);

	///////////////////////////////////////////////////////////////////////////////
	// Function : addHead
	// Parameters :	v - the item to add to the list
	///////////////////////////////////////////////////////////////////////////////
	void addHead(const Type& v);

	///////////////////////////////////////////////////////////////////////////////
	// Function : clear
	// Notes : clears the list, freeing any dynamic memory
	///////////////////////////////////////////////////////////////////////////////
	void clear();

	///////////////////////////////////////////////////////////////////////////////
	// Function : insert
	// Parameters :	index - an iterator to the location to insert at
	//				v - the item to insert
	// Notes : do nothing on a bad iterator
	///////////////////////////////////////////////////////////////////////////////
	void insert(SLLIter<Type>& index, const Type& v);

	///////////////////////////////////////////////////////////////////////////////
	// Function : remove
	// Parameters :	index - an iterator to the location to remove from
	// Notes : do nothing on a bad iterator
	///////////////////////////////////////////////////////////////////////////////
	void remove(SLLIter<Type>& index);

	///////////////////////////////////////////////////////////////////////////////
	// Function : size
	// Return : the number of items stored in the linked list.
	///////////////////////////////////////////////////////////////////////////////
	inline unsigned int size() const;

	friend class SLLIter<Type>;
};

template <typename Type>
SLList<Type>::~SLList()
{
	clear();
}
template <typename Type>
SLList<Type>& SLList<Type>::operator=(const SLList<Type>& that)
{
	if(this != &that)
	{
		this->clear();

		Node* tmp;
		Node* tail;
		for(Node*temp = that.head; temp; temp = temp->next)
		{
			tmp = new Node(temp->element,0);
			if(that.head == temp)
				head = tail = tmp;
			else
			{
				tail->next = tmp;
				tail = tail->next;
			}
		}
		this->count = that.count;
	}
	return *this;
}
template <typename Type>
SLList<Type>::SLList(const SLList<Type>& that)
{
	Node* tmp;
	Node* tail;
	for(Node*temp = that.head; temp; temp = temp->next)
	{
		tmp = new Node(temp->element,0);
		if(that.head == temp)
			head = tail = tmp;
		else
		{
			tail->next = tmp;
			tail = tail->next;
		}
		this->count = that.count;
	}

}
template <typename Type>
void SLList<Type>::addHead(const Type& v)
{
	Node *tmp = new Node(v,0);
	tmp->next = head;
	head = tmp;
	++count;
}
template <typename Type>
void SLList<Type>::clear()
{
	while(head != NULL)
	{
		Node *tmp = head;
		head = head->next;
		delete tmp;
	}
	count = 0;
}
template <typename Type>
void SLList<Type>::insert(SLLIter<Type>& index, const Type& v)
{
	if(index.curr == NULL)
		return;
	if(index.curr == head)
	{
		this->addHead(v);
		index.curr = head;
	}
	else
	{
		Node * temp = new Node(v,0);
		temp->next = index.curr;
		index.prev->next = temp;
		index.curr = temp;
		++count;
	}
}
template <typename Type>
void SLList<Type>::remove(SLLIter<Type>& index)
{
	if(index.curr == NULL)
		return;
	if( index.curr == head)
	{
		head = head->next;
		delete index.curr;
		index.curr = head;
	}
	else
	{
		Node * temp = index.curr;
		index.prev->next = index.curr->next;
		index.curr = index.curr->next;
		delete temp;
	}
	--count;
}
template <typename Type>
inline unsigned int SLList<Type>::size() const
{
	return count;
}




template <typename Type>
class SLLIter
{
	SLList<Type> * list;
	typename SLList<Type>::Node * prev;
	typename SLList<Type>::Node * curr;

public:
	///////////////////////////////////////////////////////////////////////////////
	// Function : Constructor
	// Parameters :	listToIterate - the list to iterate
	///////////////////////////////////////////////////////////////////////////////
	SLLIter(SLList<Type>& listToIterate);

	///////////////////////////////////////////////////////////////////////////////
	// Function : begin
	// Notes : moves the iterator to the head of the list
	///////////////////////////////////////////////////////////////////////////////
	void begin();

	///////////////////////////////////////////////////////////////////////////////
	// Function : end
	// Notes : returns true if we are at the end of the list, false otherwise
	///////////////////////////////////////////////////////////////////////////////
	bool end() const;

	///////////////////////////////////////////////////////////////////////////////
	// Function : operator++
	// Notes : move the iterator forward one node
	///////////////////////////////////////////////////////////////////////////////
	SLLIter<Type>& operator++();

	///////////////////////////////////////////////////////////////////////////////
	// Function : current
	// Notes : returns the item at the current iterator location
	///////////////////////////////////////////////////////////////////////////////
	Type& current() const;

	friend class SLList<Type>;

	void moveIter(const int index)
	{
		for(int i=0;i<index;++i)
		{
			if(curr == NULL)
				return;
			prev = curr;
			curr = curr->next;
		}
	}
};

template <typename Type>
SLLIter<Type>::SLLIter(SLList<Type>& listToIterate)
{
	list = &listToIterate;
	prev = NULL;
	curr = NULL;
	begin();
}
template <typename Type>
void SLLIter<Type>::begin()
{
	curr = list->head;
}
template <typename Type>
bool SLLIter<Type>::end() const
{
	if(curr == NULL)
		return true;
	else
		return false;
}
template <typename Type>
SLLIter<Type>& SLLIter<Type>::operator++()
{
	if(curr == NULL)
		return *this;
	prev = curr;
	curr = curr->next;
	return *this;

}
template <typename Type>
Type& SLLIter<Type>::current() const
{
	return curr->element;
}


#endif

A Generic Templated Dynamic Array

/////// Aaron Schie 1360283 DTS 1004
#include <cstdlib>

#ifndef _DYNARRAY
#define _DYNARRAY

template <typename Type> 
class DynArray
{
	unsigned int m_size;
	unsigned int m_capacity;
	Type * arr;

public:
	//Constructor
	DynArray();

	//Destructor
	virtual ~DynArray(void);

	// copy constructor
	DynArray<Type>(const DynArray<Type>& that);

	//assignment operator
	DynArray<Type>& operator=(const DynArray<Type>& that);

	Type& operator[](const unsigned int& index);
	const Type& operator[](const unsigned int& index)const;

	//Accessors
	unsigned int size()const{return m_size;}
	unsigned int capacity()const {return m_capacity;}
	//Methods
	void clear();
	void append(const Type& item);
	void reserve(const unsigned int& newCap = 0);

	void setsize(unsigned int a);
};

//Constructor
template <typename Type> 
DynArray<Type>::DynArray()
{
	this->m_size = 0;
	this->m_capacity = 0;
	this->arr = NULL;
}

//Destructor
template <typename Type> 
DynArray<Type>::~DynArray(void)
{
	this->clear();
}

// copy constructor
template <typename Type> 
DynArray<Type>::DynArray(const DynArray<Type>& that)
{
	this->arr = new Type[that.m_capacity];
	this->m_size = 0;
	this->m_capacity = that.m_capacity;
	for(int i = 0; i < (int)that.m_size; i++)
		this->append(that[i]);
}

//assignment operator
template <typename Type> 
DynArray<Type>& DynArray<Type>::operator=(const DynArray<Type>& that)
{
	if(this != &that)
	{
		this->clear();
		this->arr = new Type[that.m_capacity];
		this->m_size = 0;
		this->m_capacity = that.m_capacity;
		for(int i = 0;i < (int)that.m_size; i++)
			this->append(that[i]);
	}
	return *this;
}

template <typename Type> 
Type& DynArray<Type>::operator[](const unsigned int& index)
{
	return this->arr[index];
}

template <typename Type> 
const Type& DynArray<Type>::operator[](const unsigned int& index)const
{
	return this->arr[index];
}

template <typename Type> 
void DynArray<Type>::clear()
{
	delete[] this->arr;
	this->arr = NULL;
	this->m_size = 0;
	this->m_capacity = 0;
}

template <typename Type> 
void DynArray<Type>::append(const Type& item)
{
	if(this->size() == this->m_capacity)
	{
		if(this->m_capacity == 0)
			this->reserve(1);
		else
			this->reserve(m_capacity*2);
	}

	arr[this->size()] = item;
	++m_size;
}

template <typename Type> 
void DynArray<Type>::reserve(const unsigned int & newCap)
{

	if(newCap == 0 || newCap > this->capacity())
	{
		if(newCap == 0)
		{
			if(this->m_capacity == 0)
				this->m_capacity = 1;
			else
				this->m_capacity = this->m_capacity * 2;
		}
		else
			this->m_capacity = newCap;

		Type *temparr;
		temparr = this->arr;

		this->arr = new Type[this->m_capacity];

		for(int i = 0; i < (int)this->size();i++)
			arr[i] = temparr[i];

		delete[] temparr;
	}
}
template<typename Type>
void DynArray<Type>::setsize(unsigned int a)
{
	m_size = a;
}


#endif