#ifndef SLL_H
#define SLL_H
#include <iostream>
using namespace std;

//template class
template <class T>
//class SLL
class SLL
{
	//Our data in the linklist is stored in nodes
	//whichs contains data and next pointers
	struct Node
	{
		T element;
		Node* next;
	};

	//head pointer which points to the first node in the SLL
	Node* m_head;

public:

	SLL(void);
	~SLL(void);
	//Addhead() - adds a node to the begining of the linked list.
	void addHead( T value );

	//removes a head
	void removeHead();
	//clears a node completely
	void Clear();

	//Prints to screen
	void Print();

	//finds a elemnet
	bool Find( T value );

	//find and remove a element
	bool FindAndRemove( T value );

};
#endif

template <class T> SLL<T>::SLL(void)	
{
	m_head = 0;
}

template <class T> SLL<T>::~SLL(void)
{

}
template <class T> void SLL<T>::addHead( T value )
{

	// Dynamically create a new node
	Node* n = new Node;

	//Set N to value to passed node into fuction
	n->element = value;

	// Set the pointer to the current head
	n->next = m_head;

	// Point head to new headnode
	m_head = n;

}

template <class T> void SLL<T>::removeHead()
{
	// create a pointer (tmp) that points to head
	Node* tmp = m_head;

	// move head to tmps next node
	m_head = tmp->next; //alternatively, m_head = m_head->next

	//delete tmp's node
	delete tmp;
}

template <class T> void SLL<T>::Clear()
{
	while(m_head)
	{

		// create a pointer (tmp) that points to head
		Node* tmp = m_head;

		// move head to tmps next node
		m_head = tmp->next; //alternatively, m_head = m_head->next

		//delete tmp's node
		delete tmp;
	}
}

template <class T> void SLL<T>::Print()
{
	Node* tmp = m_head;
	while(tmp)
	{
		cout << tmp->element << " -> ";

		tmp = tmp->next;
	}
	cout << "X\n";
}

template <class T> bool SLL<T>::Find( T value )
{
	Node* tmp = m_head;
	while(tmp)
	{
		if(tmp->element == value)
		{
			return true;
		}

		tmp = tmp->next;
	}
	return false;
}

template <class T>
bool SLL<T>::FindAndRemove( T value )
{

	if(value == m_head->element)
	{
		removeHead();
		return true;
	}

	Node* tmp = m_head;
	Node* previous = 0;
	while(tmp)
	{
		if(tmp->element == value)
		{

			previous->next = tmp->next;
			delete tmp;

			return true;
		}
		previous = tmp;
		tmp = tmp->next;
aqwb  2 x 
	}
	return false;
}
#ifndef SLL_H
#define SLL_H
#include <iostream>
using namespace std;

//template class
template <class T>
//class SLL
class SLL
{
	//Our data in the linklist is stored in nodes
	//whichs contains data and next pointers
	struct Node
	{
		T element;
		Node* next;
	};

	//head pointer which points to the first node in the SLL
	Node* m_head;

public:

	SLL(void);
	~SLL(void);
	//Addhead() - adds a node to the begining of the linked list.
	void addHead( T value );

	//removes a head
	void removeHead();
	//clears a node completely
	void Clear();

	//Prints to screen
	void Print();

	//finds a elemnet
	bool Find( T value );

	//find and remove a element
	bool FindAndRemove( T value );

};
#endif

template <class T> SLL<T>::SLL(void)	
{
	m_head = 0;
}

template <class T> SLL<T>::~SLL(void)
{

}
template <class T> void SLL<T>::addHead( T value )
{

	// Dynamically create a new node
	Node* n = new Node;

	//Set N to value to passed node into fuction
	n->element = value;

	// Set the pointer to the current head
	n->next = m_head;

	// Point head to new headnode
	m_head = n;

}

template <class T> void SLL<T>::removeHead()
{
	// create a pointer (tmp) that points to head
	Node* tmp = m_head;

	// move head to tmps next node
	m_head = tmp->next; //alternatively, m_head = m_head->next

	//delete tmp's node
	delete tmp;
}

template <class T> void SLL<T>::Clear()
{
	while(m_head)
	{

		// create a pointer (tmp) that points to head
		Node* tmp = m_head;

		// move head to tmps next node
		m_head = tmp->next; //alternatively, m_head = m_head->next

		//delete tmp's node
		delete tmp;
	}
}

template <class T> void SLL<T>::Print()
{
	Node* tmp = m_head;
	while(tmp)
	{
		cout << tmp->element << " -> ";

		tmp = tmp->next;
	}
	cout << "X\n";
}

template <class T> bool SLL<T>::Find( T value )
{
	Node* tmp = m_head;
	while(tmp)
	{
		if(tmp->element == value)
		{
			return true;
		}

		tmp = tmp->next;
	}
	return false;
}

template <class T>
bool SLL<T>::FindAndRemove( T value )
{

	if(value == m_head->element)
	{
		removeHead();
		return true;
	}

	Node* tmp = m_head;
	Node* previous = 0;
	while(tmp)
	{
		if(tmp->element == value)
		{

			previous->next = tmp->next;
			delete tmp;

			return true;
		}
		previous = tmp;
		tmp = tmp->next;
	}
	return false;
}