// file: PairWithGcdR.cpp
// object-oriented, value semantics, recursive
// or pointer semantics

#include "PairWithGcdR.hpp"

#include <cstdlib>

	PairWithGcdR::PairWithGcdR (int new_p, int new_q)
	{
		set(new_p, new_q);
	}

	int PairWithGcdR::gcd () const
	{
		if (q == 0)
		{
			return abs(p);
		} 
		else 
		{
			//	PairWithGcdR next = PairWithGcdR(q, p % q);
			PairWithGcdR next(q, p % q);
			return next.gcd();
			/*
				PairWithGcdR * next = new PairWithGcdR(q, p % q);
				assert(next); // new successful.
				int result = next->gcd();
				delete next;
				return result;
			*/
		}
	}
