Recursive function for computing total route

How to do recursive function for the following?

RecursiveComputeRouteDistance(p1index,p2index,locations,latitudes,longitudes):
recursively computes the total distance between all waypoints (route) using computeDistance function to compute
the distance between two adjacent points. You need to recursively compute the distance for the base
case(s) and the general case(s).

This is my computeDistance function

1
2
3
4
5
6
7
8
9
10
int computeDistance(double a1,double b1,double a2,double b2)
{
	const int R=6378136;
	const float Pi =3.14159;
	float Dist=0;

	Dist= ((Pi*R)/180)* acos((cos(a1)* cos(b1)* cos(a2)* cos(b2)) + (cos(a1) *sin(b1)* cos(a2)*sin(b2)) + (sin(a1)*sin(a2)));

	return Dist;
}
Last edited on
please help
Sounds like the base case in this problem would be when you come down the last two waypoints? I'm not sure what the locations parameter is in RecursiveComputeRouteDistance(p1index,p2index,locations,latitudes,longitudes) - is this something that would be counting down as you calculate intermediate waypoints?

if (base case)
... do something
else (not the base case)
... call the function recursively, incrementing or decrementing one of the parameters so that the base case will eventually be reached
Topic archived. No new replies allowed.