Create a class DataBuffer that simulates a small fixed-size buffer commonly used in embedded systems.
The buffer uses a statically allocated array of size 20, and its effective size is determined during construction.
int size → effective buffer size (1–20)int buffer[20] → fixed internal storageint writeIndex → next write positionDataBuffer(int s)
size as follows:s < 1, set size = 1s > 20, set size = 20size = sbuffer to 0writeIndex = 0void push(int v)writeIndex < size:v in buffer[writeIndex]writeIndexvoid print()0 to writeIndex - 1Program behavior (main):
s → requested buffer sizen → number of values to pushn integers
Example Input:
5
7
1 2 3 4 5 6 7
Example Output:
1 2 3 4 5
Constraints:
Input
5 7 1 2 3 4 5 6 7
Expected Output
1 2 3 4 5