代码如下:
// This approach adds one bit to end and start pointers
// Circular buffer object
typedef struct {
int size; // maximum number of elements
int start; // index of oldest element
int end; // index at which to write new element
ElemType *elems; // vector of elements
} CircularBuffer;
int cbIsFull(CircularBuffer *cb) {
// This inverts the most significant bit of start before comparison
return cb->end == (cb->start ^ cb->size);
}
int cbIsEmpty(CircularBuffer *cb) {
return cb->end == cb->start;
}
//增大
int cbIncr(CircularBuffer *cb, int p) {
// start and end pointers incrementation is done modulo 2*size