In Java, write a method that deletes the i-th node from a circular linked list.
Java: Write a method that deletes the i-th node from a circular linked list.?
link the i+1th node previous link to the i-1
and viceversa
link the i-1 next link to i+1
Reply:My Java is probably flawed, so you may need to fix it up:
You probably have a function to get the i-th node, so assuming Item is the i-th node:
Item.previous.next = Item.next;
Item.next.previous = Item.previous;
delete(Item);
If you do not have a function to get the i-th node (assuming Item is the start of the list):
for(j=0; j%26lt;i; j++){
Item = Item.next;
}
No comments:
Post a Comment