I'm writing a class as an assignment and i am struggling on one function inside of the class. The class is called PowerArray and has, for the purposes of the question, two instance variables, one is an inner array known as data. The other is the count. Data can contain 20, but the count keeps track of the current length of the array. Now that the background is there, on to the question, I am trying to add a character to the front of the array, but I can't seem to get it to work. My current effort is below
public int addFront(char ch)
{
if(count<MAX)
{
for(int i = 0; i<count; i++)
{
data[i] = data[i+1];
}//for
data[0] = ch;
count++;
return 0;
}//if
else
return 1;
} //addFront(char)
P.S: Max is the data array's maximum size, so it's the true size of the array. Also, i'm not worried about accounting for overflow in this case, I simply don't want to preform the function.