/*****************************************
** This program demonstrates an iterative
** and a recursive approach to defining
** the max function.
*****************************************/
#include <iostream>
#include <algorithm> // defines max and min for doubles!
using namespace std;

/*****************************************
** Class def's and function prototypes
*****************************************/
class Node
{
public:
double data;
Node *next;
};

// ITERATIVE VERSION OF MAX (assume L not empty!)
double max_i(Node* L);

// RECURSIVE VERSION OF MAX (assume L not empty!)
double max_r(Node* L);

/*****************************************
** MAIN
*****************************************/
int main()
{
// Get list of values from user
Node *L = 0;
double x;
while(cin >> x)

// Print maximum using both iteration and recursion
cout << "Maximum (via iteration) is: "
<< max_i(L) << endl;

cout << "Maximum (via recursion) is: "
<< max_r(L) << endl;

return 0;
}

/*****************************************
** Function definitions
*****************************************/

// ITERATIVE VERSION OF MAX (assume L not empty!)
double max_i(Node* L)
{
double m = L->data;
for(Node *p = L->next; p != 0; p = p->next)
m = max(m,p->data);
return m;
}

// RECURSIVE VERSION OF MAX (assume L not empty!)
double max_r(Node* L)
{
if (L->next == 0)
return L->data;
else
return max(L->data,max_r(L->next));
}