Just try to understand following program. I have written that program for you. It is very easy process to remove any specific item from linked list. Just insert index number of that particular elements and then it automatically remove from linked list.
Code:
public void addNode(int coeffs, int powers)
{
if (heads == null)
{
heads = new Node(coeffs, powers, null);
degrees = powers;
}
else
{
Node p = heads;
Node lasts = null;
while (p != null)
{
{
if (lasts == null)
heads = new Node(coeffs, powers, p);
else
lasts.next = new Node(coeffs, powers, p);
degrees = powers;
break;
}
last = p;
p = p.next;
}
if (p == null)
{
lasst.next = new Node(coeffs, powers, null);
}
}
}
Bookmarks