Please help

Hello guys,
I was wondering if you could help me out with a class function definition I need to make. Maybe its just getting late but I can't come up with the right definition for the function that returns the location in an integer array of maximum size 20 or 0 if there is no such value. Here's my code.

This function should insert a value at a specified location (if room) if there is no room it should send a false return statement. There's something in here I can't catch Hopefully, you guys can find the error. Thank you.

One more time...

Hi again,
I know what I am doing wrong I just do not know how to track the error and where to find it. My element variable is supposed to keep track of the last element in the array. Maybe my constructor will clarify the point.

A couple things. The first deals with the ++ operator. What ++ does is actually modify the operand it is working on (that is, you don't need x = x++).

Similarly, x++ and ++x return different things. x++ returns the value of x before it was incremented, while ++x returns the value after it was incremented.

As a consequence, x=x++ doesn't change x at all, while x=++x is equivalent to ++x; followed by x=x. I suspect this is a large part of your problem. You are never really modifying 'element', and hence, overwriting the same value over and over.

Also, your 'element' variable would probably be best keeping track of one-past the last element (at least the way it is setup now). Note that this 'one-part' value is also the same as the current length of the list.

If it is marking the last element in the list, then you need to increment it before writing to that space in the list (otherwise this will overwrite the last element, and then move on). If it is marking length, then you'd assign to that space, and then increment. Also, note that if your marking the last element, than the condition (element < SIZE) will allow you to increment to element==SIZE, and write to that space (which is of course outside the bounds of the array).

One other thing, since an array is 0-based, setting element to 0 in the constructor actually sets it to one-past the last element (which is theoretically at the -1 index, in this case). This is because the list contains no elements, so clearly 0 is not where the last one is.

Hope this helps.

The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.