IteratorDemo

# IteratorDemo - } double average(LinkedList& l) { double...

This preview shows pages 1–2. Sign up to view the full content.

#include <iostream> #include <fstream> #include <cmath> #include "LinkedList.h" using namespace std ; double average(LinkedList& l); double variance(LinkedList& l, double avg); int main () { LinkedList l; cout << "Enter some numbers: "; while(true) { int val; cin >> val; if(!cin) break; l.addToBack(val); } double avg = average(l); cout << endl << "Input has average " << avg << " and variance " << variance(l, avg) << endl;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } double average(LinkedList& l) { double sum = 0; int count = 0; for(LinkedListIterator i = l.begin(); i != l.end(); i.advance()) { sum += *i; count++; } return sum / count; } double variance(LinkedList& l, double avg) { double sum = 0; int count = 0; for(LinkedListIterator i = l.begin(); i != l.end(); i.advance()) { sum += pow((*i - avg), 2); count++; } return sum / count; }...
View Full Document

## This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

### Page1 / 2

IteratorDemo - } double average(LinkedList& l) { double...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online