I'm trying to implement a circular linked list that uses arrays. I've written and tested my class known as "Buffer". This is the description of buffer class:
"The Buffer class implements a circular array buffer. The member variable m_buffer is a pointer to an array of integer values. The array will be defined by allocating memory dynamically. An object of Buffer class also contains the member variable m_next which is a pointer to another Buffer object. This member variable will be used by the BufferList class for implementation of the linked list."
My buffer class, as far as I know and from what I've tested, works correctly. Now I'm moving on to writing BufferList and I'm a bit stuck. I don't really fully understand what it means to create the object. I just want to know if I'm on the right track?
These are the instructions for the constructor:
Constructor creates a BufferList object which contains the first buffer of this object with the size minBufCapacity. If minBufCapacity is less than 1, the constructor creates a buffer with default size DEFAULT_MIN_CAPACITY. The constructor also initializes the member variables of the class.
This is what I've written:
1 2 3 4 5 6 7 8
BufferList::BufferList(int minBufCapacity){
Buffer aBuffer(DEFAULT_MIN_CAPACITY);
//member variables of class
Buffer * m_cursor = nullptr;
int m_listSize = 0;
int m_minBufCapacity = 0;
}
just to be clear this asks for a standard circular buffer, not a circular linked list.
a couple of tips:
mod will circle back...
int x[10];
for(int i = 0; i < 42; i++)
x[i%10] = i;
for(int i = 0; i < 10; i++)
cout << x[i] << endl; //it contains 42, 41, 40, 39, .....
and you may want to track current capacity and positions of data depending on how you read from it. typically you have the current reading location and the current writing location and usually read and write need to be in sync such that you don't read more than is in it or write new before some of the old was read. Getting them in sync can be tricky for some use cases. Its an aggravating data structure that works better in hardware and is sort of limiting as a software construct.