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.
Code:
List::List()
// constructor for list object - has to create the list object and print out message that
// object has been instantiated
{
element = 0;
cout << "Creating List Object\n";
}
I then have to write two functions for Insert. The user has the option to either:
Insert(int value);
OR
Insert(int pos, int value);
My functions are as follows:
Code:
bool List::Insert(int value)
// Inserts a number at the end of the list(if there is enough room)
{
if (element < SIZE){
list_array[element] = value;
element = element++;
return true;
}
else{
cout << "*** Invalid list position number\n";
return false;
}
}
Code:
bool List::Insert(int pos, int value)
// inserts a number in the list, possibly in the middle(if room, and if valid position given)
{
if ((element < SIZE) && (pos > 0)){
// shift all values at pos, one element to the right
for(int i = element; i >= pos; i--)
list_array[i + 1] = list_array[i];
// insert new value
list_array[pos] = value;
// increase the size of the array
element = element++;
return true;
}
else{
cout << "*** Invalid list position number\n";
return false;
}
}
Please let me know if I am even close.... it really is frustrating spending three hours and getting nowhere... any feedback will be most appreciated.