data-structures · intermediate · ~15 min
Compute occupancy in a circular buffer.
Implement int ring_count(int head, int tail, int cap) returning the number of items between head (front) and tail (next free slot) in a ring buffer, where items wrap around. 0 <= head,tail < cap.
int ring_count(int head, int tail, int cap) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.