IteratorDemo

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

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

View Full Document Right Arrow Icon
#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;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
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 Right Arrow Icon
Ask a homework question - tutors are online