// linklist.h
//linked list header file
#include <iostream>
using namespace std;
// node structure
#ifndef LINKLIST_H
#define LINKLIST_H
template <class T>
class TList{
private:
typedef struct nodetag{ 
	   T item;        //the data
	   nodetag *next;   //a pointer to the next node
}node;                  // typedef allows us to refer to the structure
						//nodetag as node
	node *head;
	node *current;

public:
	TList();

//linked list basic functions
    void deleteNext(void);  //delete next node in list           
    void insertAfter(T data);  //insert a node after the current node
    void gotoNextNode(void);//move on to next node
	bool endOfList(void);
	T getNodeItem(void);
    T getNextNodeItem(void);
	void resetCurrent(void);

};

//class definitions here now
template <class T>
TList<T>::TList() //constructor
{
	head = new(node);
    current = new(node); 
	head->next = NULL;
    current = head;
}
template <class T>
void TList<T>::deleteNext(void)
{
	node *ptemp;
	ptemp=current->next;
	if (current->next !=NULL)   //can't delete anything after the end of the list!
	{
		current->next=current->next->next;  //current node's next pointer
								//leap frogs current next node
			  					// and therefore points to next but one node
        delete(ptemp);        //free memory associated with leap-frogged node
	}
}
template <class T>
void TList<T>::insertAfter(T data)
{
 	node *x;           //pointer to the new node
	x = new(node);      //reserve space for new node and get its address
	x->item = data;     // put data in the new node
	x->next = current->next; //get new node to point to the old next node
    current->next = x;       // get current node to point to new node
}



template <class T>
void  TList<T>::gotoNextNode(void)//move on to next node
{
    if(current->next != NULL)
	     current=current->next;
}

template <class T>
void TList<T>::resetCurrent(void)
{
    current = head;
}


template <class T>
bool TList<T>::endOfList(void)
{
    if(current->next == NULL)
  	    return 1;
    else 
	    return 0;
}

template <class T>
T TList<T>::getNodeItem(void)
{
		return current->item;
}

template <class T>
T TList<T>::getNextNodeItem(void)
{
		return current->next->item;
}


#endif
