Please send questions to
st10@humboldt.edu .
/*--------------------------------------------------
created by st10 at Sun Nov 16 23:55:26 PST 2003
--------------------------------------------------*/
#include <iostream>
#include "sumCostsI.h"
using namespace std;
/*--------------------------------------------------
Contract: sumCostsI : MyNodePtr -> double
Purpose: sum the costs of the nodes from the
MyNode pointed to by nPtr to the end
of the linked list
Examples: if nPtr points to a node with cost 1.50,
whose nextPtr points to a node with cost 2.30,
whose nextPtr points to a node with cost 0.50,
whose nextPtr points to a node with cost 1.13,
whose nextPtr points to NULL, then
sumCostsI(nPtr) == 5.43
--------------------------------------------------*/
double sumCostsI (MyNodePtr nPtr)
{
double sumCosts = 0;
MyNodePtr currPtr = nPtr;
// "walk" through nodes from here to end of
// list, summing the costs seen;
while (currPtr != NULL)
{
sumCosts += currPtr->get_cost();
currPtr = currPtr->get_nextPtr();
}
return sumCosts;
}