/*	Linked List program */

#include <iostream.h>
#include <lvpstring.h>

using namespace std;	// October 5, 2001

typedef lvpstring ItemType;

// Nodetype is used by ListClass
struct NodeType {
	ItemType Data;
	NodeType *Next;
};

class ListClass {
public:
	ListClass();    // Instantiates an empty list
	~ListClass();   // Deallocates memory used by list
	void AddAtFront(const ItemType &Item);    // Adds new node to front of list
	void Write(ostream &Output) const;    // Writes list data in order
private:
	NodeType *First;
};
//--------------------------------------------------------------------------------
ListClass::ListClass()
	: First(NULL)  // Sets list to empty
{
}
//--------------------------------------------------------------------------------
ListClass::~ListClass()
/*	Post: Memory used by list deallocated */
{
	NodeType *Curr = First;
	NodeType *Previous;
	while (Curr != NULL) {
		Previous = Curr;
		Curr = (*Curr).Next;
		delete Previous;
	}
}
//--------------------------------------------------------------------------------
void ListClass::AddAtFront(const ItemType &Item)
/*	Post: New node containing Item added at front of list */
{
	NodeType *Temp;
	Temp = new NodeType;
	(*Temp).Data = Item;
	(*Temp).Next = First;
	First = Temp;
}
//--------------------------------------------------------------------------------
void ListClass::Write(ostream &Output) const
/*	Post: Write the data of nodes to Output */
{
	NodeType *Curr = First;
	while (Curr != NULL) {
		Output << (*Curr).Data << endl;
		Curr = (*Curr).Next;
	}
}
//--------------------------------------------------------------------------------
int main()
{
	ListClass L;
	L.AddAtFront("Sandburg");
	L.AddAtFront("Strand");
	L.AddAtFront("Angelou");
	L.Write(cout);
	return(0);
}

