Suppose there's an array defined as A=new int[max] whom which you want to insert entries in:
The void insert( const Item_type &item ) function takes i's and inserts them in A in REVERSED order (adds to the left end):
for (int i=0; i<10; i++)
A = [9, 8, 7, ..., 1, 0]
In the header file, other than max, the following are defined:
int front; representing the first used entry in the array,
int count; representing number of items in A.
Assume when A was created front and count were both set to zero.
If we were to insert the i's in regular order (added to the right end) the definiton for insert( ... ) in the .cpp definition file would look like:
which, after the for-loop, would output:
void class::insert( const Item_type &item )
A = [0, 1, 2, ..., 9]
How would you define insert() to add the item to the left instead (i.e. in reversed order)? Apparently due to 'circularity' that occurs in this process, no shifting is necessary.
A word of wisdom is appreciated.
P.S> The insert() function should be able to handle all situations. i.e. the following is not what I am asking for:
By 'all situations' I mean that if you have B with 6 items already in it, insert(15) should correctly add 15 to the front (left).