Sunday 8 September 2013

remove the i'th link in a doubly linked list

remove the i'th link in a doubly linked list

I want to remove a link in the location on the linked list that is passed
to this method, however it is not working. I think my code is really bad,
if the index is 0 then I think it will give me an error:
public void remove(int index)
{
DLink iterator=_firstLink;
int count=0;
while(iterator!=_lastLink)
{
iterator=iterator._next;
count++;
if(count>=index)break;
}
if(index==count)
{
iterator._previous = iterator._next;
_size--;
}
else
{
try
{
throw new Exception("IndexOutOfBoundException");
}
catch (Exception e1)
{
e1.printStackTrace();
}
}
}

No comments:

Post a Comment