problem shifting (copying) array elements in a list
I am trying to add points to the beginning of a list. However, I cannot seem to debug the insertBeginning( ) method. I am faced with a problem that overwrites certain array elements. If I can get any help I would greatly appreciate it.
Thanks,
I have included a sample run and some code.
The following url contains both the main and the class files.
http://lbbmx.com/java/
publicvoid appendZ ( Point newPoint )// used w/ insertBeg method
{
size++;
cursor=0;
ptlist[cursor]= newPoint;
}
publicvoid insertBeginning ( Point newPoint )// Insert begin.
{
if(this.isEmpty())
{append(newPoint);}
else
{
cursor=0;
for(int i=size; i>cursor; i--)
{
ptlist[size]= ptlist[size-1];//pt[1]=pt[0]
}
this.appendZ(newPoint);
Here is a sample run:
Commands:
+ x y : Append point (x,y) to the end of the list
# x y : Insert point (x,y) at beginning
Q: Quit the test program
Empty list
Command: +1 1
Append (1,1)
size = 1cursor = 0
01234567
(1,1)
Command: #2 2
Insert (2,2) at beginning
size = 2cursor = 0
01234567
(2,2)(1,1)
Command: #3 3
Insert (3,3) at beginning
size = 3cursor = 0
01234567
(3,3)(1,1)(1,1)

