//Implementation File:	smallLinked.cpp

#include "smallLinked.h"

	//List IMPLEMENTATION
list::list()	//Constructor
:	front(NULL), rear(NULL) //member initializer list
{
}

list::list(const list & l)
{
	*this = l;
}

	
list & list::add_front (const int number)
{
	node * temp=new node;

	temp->data=number;
	temp->next=front;
	front=temp;

	if (rear==NULL)	//list empty to start
		rear=front;

	return *this;
}

list & list::remove_front ()
{
	node * temp = front->next;
	
	delete front; //gives memory back to the pool
	front = temp; //moves front one down the line

	return *this;
}

list & list::add_rear (const int number)
{
	node * temp = new node;

	//Put appropriate data in temp
	temp->data = number;
	temp->next = NULL;

	rear->next = temp; //connect temp up to rest of list

	rear = temp; //move rear pointer to temp

	return *this;
}


//My attempt doesn't work properly, but the idea is to cycle through
//the list keeping a pointer that's one behind the temp pointer
//so that you can update the node just before the rear.
list & list::remove_rear ()
{
	node * temp;
	node * previous;
	for (temp=front; temp!=NULL; temp=temp->next)
	{
		back = temp;
	}
	back->next = NULL;

	delete rear;

	return *this;
}

/*
bool list::empty() const
{
	return (front==NULL);
}
*/

	//friend function IMPLEMENTATION
ostream & operator<< (ostream & out, list & L)
{
	node *temp;

	for (temp=L.front; temp!=NULL; temp=temp->next)
		out << temp->data << endl;

	return out;
}
