// LinkedList .h

// This file declares (and defines some elements of) a singly linked list.
// Some source code is inlined for efficiency.

// Author: Dr. Jeffrey Blessing

#define WIN32_LEAN_AND_MEAN			// speeds up non-MFC builds
#include <cstdlib>					// defines NULL
#include <iostream>					// used when overloading <<
using namespace std;

// Declare the List class so the Node class can forward reference it.

class LinkedList;

// The Node class defines the elements in the list.

class Node
{
public:
	Node(double d=0, Node* p=NULL): data(d), next(p) { }
	friend class LinkedList;
	friend ostream& operator<<(ostream& os, const LinkedList& src);
private:
	double	data;
	Node*	next;
};

// The LinkedList class declares the list properties.

class LinkedList
{
public:
	LinkedList();		// constructor
	void add(double d);	// adds to the end of the list
	double getNext();	// returns the next element
	void start();		// resets the pointer to start of list
	~LinkedList();		// destructor
	LinkedList(const LinkedList& src);	// copy constructor
	LinkedList& operator=(const LinkedList& src);	// assign. op.
	friend ostream& operator<<(ostream& os, const LinkedList& src);
private:
	Node*	head;		// start of list pointer
	Node*	tail;		// end of list pointer
	Node*	ptr;		// current element pointer
};

// The linked list implementation follows:

inline LinkedList::LinkedList()
{
	// create header cell
	head = tail = ptr = new Node();
//	ptr->next = NULL;
}

inline void LinkedList::add(double d)
{
	// add to end of the list
	tail->next = new Node();
	tail = tail->next;
	tail->data = d;
//	tail->next = NULL;
}

inline double LinkedList::getNext()
{
	ptr = ptr->next;
	return ptr->data;
}

inline void LinkedList::start()
{
	ptr = head;
}