Skip to content

Instantly share code, notes, and snippets.

@jneem
Last active March 9, 2022 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jneem/4e3e80c0f1a227cbf440625ea6b38bb1 to your computer and use it in GitHub Desktop.
Save jneem/4e3e80c0f1a227cbf440625ea6b38bb1 to your computer and use it in GitHub Desktop.
// Guaranteed to return a value strictly bigger than x (as long as x is finite).
// If x is infinite, will drain the list and then return infinity.
double next(list<double> *const ys, double x)
{
while (!s->empty())
{
double y = /* some computation depending on x and ys->front() */;
if (y > x)
return y;
s->pop_front();
}
return infinity();
}
void loop(list<double> const* ys)
{
double x = -infinity();
while (!s->empty()) {
x = next(ys, x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment