Posted: August 20th, 2024
the specified element at the specified position in
Can someone explain why
temp.setNext(current.getNext()); has been used I am not understanding
public void add(Object data, int index)
// post: inserts the specified element at the specified position in this list.
{
Node temp = new Node(data);
Node current = head;
// crawl to the requested index or the last element in the list,
// whichever comes first
for(int i = 1; i < index && current.getNext() != null; i++)
{
current = current.getNext();
}
// set the new node's next-node reference to this node's next-node reference
temp.setNext(current.getNext());
// now set this node's next-node reference to the new node
current.setNext(temp);
listCount++;// increment the number of elements variable
}
Order | Check Discount
Tags:
Ace My Homework: Essay Help,
Assignment Help: USA's #1 Online Assignment Writing Service,
Do My Assignment for Me Online - Write Academic Papers,
Reliable Online Homework Help For You,
UK Homework Study Bay: Assignment Homework Help & Homework Answers,
Write My Assignments AU - Online Assignment Maker - Writing Services
Sample Essays, Assignments & Research Topics Ideas