I'm defining the %26lt;%26lt; operator and defining the %26gt;%26gt; operator. This will take in one integer and append it on to the end of the array. This means that I will need to grow the array (and hence need access to private data members - it is much less awkward, and faster, to have direct access than to go through intermediary functions). Growing an array consists of making a new array that is 1 space larger, copying all of the elements, deleting the old array, and assigning the new array to the old array's variable. Make sure to check if the array was actually created before deleting it (check the len variable).
this is using classes and header files,
my array name is arr
my lenght is len
so how can i do this
any suggestions, thanks
Need help on c++?
Actually, making a new array, and copying values from the old is right on the money. In fact, this *is* what vector::push_back() does.
Reply:Making a new array and copying all of the old values over is a very bad idea. Arrays, are not meant to be resized, they are meant for when you have an absolute maximum number of elements to include in the array.
Using Vectors is a much better idea, because you can simply use vector::push_back to add an element to the end. Another idea would be a linked list, but the end its all up to you.
For help on vectors, visit:
http://www.cppreference.com/cppvector/in...
Reply:I'd suggest working with the collection classes like vector, deque and queue.
Good luck
Reply:It sounds like you already know what to do.
Do your own homework
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment