You are implementing a circular buffer using a C struct.
The buffer is defined as:
typedef struct {
int buffer[100]; // Fixed memory for data
int head; // Write index
int tail; // Read index (not used here)
int count; // Number of elements in buffer
int capacity; // Maximum number of elements buffer can hold
} CircularBuffer;
Implement the function:
void insert_circular(CircularBuffer *cb, int value);
This function should:
Constraints
Example-1
Input: n = 5, values = [10, 20, 30, 40, 50]
Output: buffer = 10 20 30 40 50
Example-2
Input: n = 3, values = [1, 2, 3, 4]
Output: buffer = 1 2 3
(4 is ignored as the buffer is full)
Input
5 5 10 20 30 40 50
Expected Output
10 20 30 40 50