Find the distance between the two closest elements in an array of numbers.

Hi cplusplus.com forum,

I'm trying to compile this algorithm below in C++. Any ideas please?

// Find the distance between the two closest elements in an array of numbers.
// Minimum Distance
// dmin = infinity;
// for i = (i to n - 2) do
// for j = i + 1 to n - 1 do
// temp = A[i] - A[j]
// if temp < dmin;
// dmin = temp;
// return dmin;
closed account (o3hC5Di1)
Hi there,

As said in another one of your posts, please try this first for yourself and come back to us when you run into specific problems, preferably including your code.

Asking us to do the work for you is not going to make you learn anything.

All the best,
NwN
Topic archived. No new replies allowed.