Skip to content

Instantly share code, notes, and snippets.

@PedroHLC
Created June 29, 2016 00:13
Show Gist options
  • Save PedroHLC/45e1195498b8554c6ffcb481fb0de0d6 to your computer and use it in GitHub Desktop.
Save PedroHLC/45e1195498b8554c6ffcb481fb0de0d6 to your computer and use it in GitHub Desktop.
Min Max ala CAP style
#include <stdio.h>
struct POSICAO {
double x;
double y;
};
struct POSICAO achar_min_max(int qtd_pontos, struct POSICAO *pontos) {
if(qtd_pontos == 1) {
return pontos[0];
}
struct POSICAO *ponteiro;
struct POSICAO min_max=pontos[0];
for(ponteiro = &pontos[1]; ponteiro < &pontos[qtd_pontos]; ponteiro++) {
if(ponteiro->x < min_max.x)
min_max.x = ponteiro->x;
if(ponteiro->y > min_max.y)
min_max.y = ponteiro->y;
}
return min_max;
}
int main() {
struct POSICAO pontos[5] = {
{0, 0},
{1, 1},
{2, 2},
{3, 3},
{4, 4},
{5, 5}
};
struct POSICAO min_max;
min_max = achar_min_max(5, pontos);
printf("MinMax: (%lf, %lf)\n", min_max.x, min_max.y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment