I have the Node class that helps me create a list.
class Node
{
E info;
Node next;
Node (E x)
{
next = null;
info = x;
}
}
Then I have class List.
public class List<E>
{
private Node headNode;
// some methods like addToList(). They work.
// Problem here!
public void exchangeNodes(int a, int b)
{
Node lead = head;
while (lead != null)
{
// here I wrote a bunch of noob code that if you looked at it your eyes would hurt.
}
}
TestClass
public class TestClass
{
List myList = new List();
// populating the list with strings.
myList.add("a");
myList.add("b");
myList.add("c");
myList.add("d");
myList.add("e");
myList.add("f");
myList.add("g");
myList.exchange(2, 5); // giving it position numbers to exchange.
}
The big problem is I can't get it to switch the Node's position on the list without destroying Nodes (I lose the reference to pointers when I switch). Clearly Nodes and me don't like each other
From the TestClass I want to say exchange what's on position 2 with what is on position 5.
Please help.






