//lab170412.c
#include <stdio.h>
#include <stdlib.h>

//AWOC that els > 0, return INDEX OF (first)
//smallest element
//NO LOOPING
unsigned minIndex(const double a[], unsigned els);

//AWOC (assume w/o checking) that els > 0
//return the smallest element
//NO LOOPING
double minVal(double a[], unsigned els);
double minValHelper(double a[], unsigned els, double min);

void show(const double a[], const unsigned els);
void showValues(const double min, const unsigned els, char fname[]);

int main()
{
	char fname[] = "main";
	unsigned size = 3;
	double x, y;
	double a[] = {1, -2, -3, -4, 5, -4, -4};
	double b[] = {-100, 5, 73.2, 99, 100000001, -10000001, 17, -10000001};
	double c[] = {30, -10, 20};

	show(c, size);
	showValues(0, size, fname);
	x = minVal(c, size);
	y = minIndex(c, size);
	printf("Min value a[]: %f\n", x);
	//printf("Min index a[]: %u\n", y);
	//printf("Min value b[]: %f\n", minVal(b, size));
	//printf("Min index b[]: %u\n", minIndex(b, size));

	return 0;
}


double minVal(double a[], unsigned els)
{
	char fname[] = "minVal";
	double min = a[0];
	showValues(min, els, fname);
	//the minimum value in an array is either the first el
	//of the minimum number in the REST of the array
	//whichever is smaller
	min =  minValHelper(a, els, min);
	showValues(min, els, fname);
	return min;
}

double minValHelper(double a[], unsigned els, double min)
{
	char fname[] = "minValHelper";
	showValues(min, els, fname);
	if(els - 1 == 0)
	{
		printf("no change here.\n");
		showValues(min, els, fname);
		return min;
	}
	if (min > a[0])
	{
		min = a[0];
		//showValues(min, els, fname);
	}
	minValHelper(a+1, els-1, min);
	return min;
}

unsigned minIndex(const double a[], unsigned els)
{
	return 0;
}

void show(const double a[], const unsigned els)
{
	printf("[%u]: ", els);

	for (unsigned i = 0; i < els; i++)
	{
		printf("%s%f", i ? ", " : " ", a[i]);
	}
	printf("\n\n");
}

//void showValues(const double min, const unsigned els)
void showValues(const double min, const unsigned els, char fname[])
{
	static unsigned count = 1;
	printf("count: %u\n", count);
	printf("func: %s\n", fname);
	printf("min: %f\n", min);
	printf("els: %u\n\n", els);
	count++;
}
