#include <cstdio>
#include <cassert>
constexpr static std::size_t TABLE_SIZE = 6;
std::size_t distance_between(const int * table, std::size_t size, int left_value, int right_value) {
assert(size > 0);
const int * last_ptr = table + size - 1;
while ((table < last_ptr) && ! ((*table == left_value) && (*last_ptr == right_value))) {
(*table != left_value) && ++table;
(*last_ptr != right_value) && --last_ptr;
}
return (last_ptr - table);
}
int main() {
int table[TABLE_SIZE] = {0, 1, 0, 0, 1, 0};
printf("Distance, left %d, right %d: %u\n", 0, 1, distance_between(table, TABLE_SIZE, 0, 1));
printf("Distance, left %d, right %d: %u\n", 1, 0, distance_between(table, TABLE_SIZE, 1, 0));
}
Przypadek brzegowy (jednej lub obu liczb nie ma w tablicy lub tablica ma 0 długości), pozostawiam Tobie.