Please send questions to
st10@humboldt.edu .
/*--------------------------------------------------
created by st10 at Sun Nov 16 23:55:26 PST 2003
--------------------------------------------------*/
#include <iostream>
#include "sumCosts.h"
using namespace std;
/*--------------------------------------------------
Contract: sumCostsR : 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
sumCostsR(nPtr) == 5.43
--------------------------------------------------*/
double sumCostsR (MyNodePtr nPtr)
{
// base case (non-recursive case --- where
// recursion STOPS)
if (nPtr == NULL)
{
return 0;
}
// recursive case (one that calls a "smaller"
// version of itself)
else
{
return nPtr->get_cost() +
sumCostsR( nPtr->get_nextPtr() );
}
}