Answer:
Step-by-step explanation:
The following code is written in Java. Both functions traverse the linkedlist, until it reaches the desired index and either returns that value or deletes it. If no value is found the function terminates.
public int GetNth(int index)
{
Node current = head;
int count = 0;
while (current != null)
{
if (count == index)
return current.data;
count++;
current = current.next;
}
assert (false);
return 0;
}
public int removeNth(int index)
{
Node current = head;
int count = 0;
while (current != null)
{
if (count == index)
return current.remove;
count++;
current = current.next;
}
assert (false);
return 0;
}