You don't. The array itself never changes size. When the current pointer reaches the end of the array then just reset the current pointer back to the beginning of the array -- hence its name is "circular".
my homework assignment is to make a circular array and grow it. I have to grow the circular array. Unfortunately, it is more complex than just making a temporary array, moving everything into there, and continuing. I just don't know how to do it :(
IMO that defeats the purpose of a circular array. But anyway, just make it a pointer and allocate new memory when needed, similar to what gerard mentioned previously. When the current pointer reaches the current maximum size then allocate a new array of larger size, copy the contents of the current array into the new array, then delete the current array. Not difficult to do once you understand the algorithm.
Once you get that part working then you will have to be concerned about reads from the circular array. You will have to have two temp pointers, one for reading and the other for writing. If the data is not read at least as fast as its written, then the array will eventually fill up and there will not be any more room for writing without overwriting existing data that has not been read. This situation can happen anywhere withing the array, not just at the extreme end of the array.
Thank you; however, I already got it working without the use of any pointers. I just need help with the grow part. How would I implement it using back, current_size, maximum_size, and the array.
I have tried just making a temporary array, storing the contents from the old array into the new array, and then going from there. Yet, the problem with the circular array is that it does not remove the values that were popped off of the queue. So, if those values will still transfer over to the new array, but I don't want them there.
When I said pointers I also meant the items you have already coded. You can code them as either pointers or integers. In any event the array itself will have to be a pointer so that you can allocate it with new operator. For now don't worry about coping old data that has already been read. It will eventually get overwritten with new incoming data so copying old data is not really a problem. You just have to adjust the pointers (integers) to accommodate the array's new increased size.
At this point we really can't help you much more without seeing the code you have already written. There are just too many different ways to do it.
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...