// Justin C. Miller
// University of Wisconsin Oshkosh
// Made for: http://www.geocities.com/neonprimetime.geo/index.html
// Date: 2001
// Borland Builder 4.0
//
// Link List Member Functions
//

#include 
#include 
#include "LList.h"

template 
LList::~LList()
{
	Node * p , *q;
	p = head->next ;
	while(p != head)
	{
		q=p ;
		p=p->next ;
		delete q ;
	}
	delete head ;
	head = 0 ;
}

template 
LList::LList(const LList & list) :head(new Node)
{
	Node * p ;

	head->next = head ;
	cur = head ;
	for (p = list.head->next ; p != list.head ; q = p->next)
	{
		InsertAfter(*(p->data)) ;
		cur = cur->next ;
	}
}

template 
void LList::Previous()
{
	Node * tmp = head ;

	if(head->next == head)
		cur = head ;
	else
	{
		while(tmp->next != cur)
			tmp = tmp->next ;
		cur = tmp ;
	}
}

template 
bool LList::End() const 
{return (head == cur) ;}

template 
void LList::ExtractPosition()
{
	Node * temp ;

	if(cur == head) return ;
	temp = cur ;
	Previous() ;
	cur->next = temp->next ;
	delete temp ;
}

template 
bool LList::Find(const T&x)
{
	cur = head->next ;

	while(cur != head)
		cur = cur->next ;
	if(cur = head) return false ;
	else return true ;
}

template 
void LList::First()
{cur = head->next;}

template 
void LList::Front()
{cur = head ;}

template 
T& LList::GetData() const
{return *(cur->data) ;}

template 
void LList::InsertAfter(const T&x)
{
	Node * tmp = new Node ;

	tmp->data = new T(x) ;
	tmp->next = cur->next ;
	cur->next = tmp ;
}

template 
void LList::InsertBefore(const T&x)
{
	Node * pre, *tmp = new Node ;

	pre = cur ;
	Previous() ;
	cur->next = tmp ;
	tmp->next = pre ;
	tmp->data = new T(x) ;
}

template 
bool LList::IsEmpty() const 
{return (head->next == head) ;}

template 
void LList::Last()
{
	cur = head ;
	while(cur->next != head)
		cur = cur->next ;
}

template 
void LList::Next()
{cur = cur->next ;}

template 
void LList::Reverse()
{
	Node * previous = head ;
	cur = previous->next ;
	Node * thenext = cur->next ;

	do
	{
		cur->next = previous ;
		previous = cur ;
		cur = thenext ;
		thenext = thenext->next ;
	}while(previous != head) ;
}

template 
int LList::Size() const 
{
	int count = 0 ;
	Node * tmp = head->next ;

	while(tmp != head)
	{
		count++ ;
		tmp = tmp->next ;
	}
	
	return count ;
}

template 
void LList::SetData(const T&x)
{*(cur->data) = x ;}

    Source: geocities.com/neonprimetime.geo/cpp/cpp_SourceCode

               ( geocities.com/neonprimetime.geo/cpp)                   ( geocities.com/neonprimetime.geo)