//File:	link_driver2.cpp
#include "linked2.h"
#include <iostream>
#include <string>
using namespace std;

template <typename T>
T average(const myList<T> & L)
{
	T number, sum=0;
	int k=0;
	myList<T>::ListIterator i(L);
	while (i.next(number))
	{
		sum += number;
		k++;
	}
	
	return sum/k;
}

int main()
{
	myList<> L;
	
	L.add_front(24);
	L.add_front(36);

	cout <<L << endl;
	
//The following averaging code requires access to the list private field, front
/*	int sum=0, k=0;
	
	for (node * temp=L.front; temp != NULL; temp=temp->next)
	{
		sum += temp->data;
		k++;
	}
*/


//The ListIterator class comes to the rescue
	cout << "Average=" << average(L) << endl;

	return 0;
}
