First up, you've defined the above code as an interface, not as a class... an interface only contains definitions of methods which when a class says it implements an interface, the class must contain the methods, with implementatiom, of the methods defined in the interface eg:
CODE
public interface myInterface
{
int getInteger();
String whoseYourDaddy(int NameIndex);
}
public class myClass implements myInterface
{
public int getInteger() //implements the method defined in myInterface
{
return 43;
}
public String whoseYourDaddy(int NameIndex) //implements the other method in myInterface
{
return Names[NameIndex];
}
public myClass() //a contructor
{
//...
}
public void doNothing()
{
//a random method
}
String[] Names;
}
it would also help you to declare
head,
move,
count and
n. might also help you to correctly close it off after your
tostring() method, youre missing a brace
} at the end of it all.
Youve also cut and pasted the
public void add(int index, Object o) straight out of the method above it. Instead you are going to want to keep track of the current index of the Node. If current == null before the requested index you just add it to the end of the list, otherwise you add it before the Node with the index of
index.
Looking at the
remove method i think you forgot to post the first half of the method... neither
n nor
move are defined and im pretty sure youre using them as local variables? No offence but this method is kinda bad. Ill point out some wrong points and why but i think this one needs you to think it through, which is why im telling you and not giving you the solution.
CODE
//Removes the element at the specified position in this list.
public Object remove(int index){
if (move == n) { // n and move are undefined this will break your program, im also going to assume that 'move'is going to be the node after 'n' which presumably is the node at position 'index'
move = n.getNext();
}
else {
Node tmp = move;
while (tmp.getNext() != n) tmp = tmp.getNext();// youve assigned tmp to be the node after 'n' already so all this will do is search through the remainder of the List and then throw an Exception, i think what you were trying to do was find the node before 'n'? so try assigning tmp to 'head' instead of 'move' and go from there.
tmp.setNext( n.getNext() ); //this line will work but if my earlier assumptions are correct saying [i]tmp.setnext(move);[/i] would be more efficient
}
finally this method expects you to return something, which you dont do. assuming again that
n is the node at position
index then add in
CODE
return n;
at the end.
i dont think thats all that could be said about the code but unfortunately my time is up and i need to get back to work. hope that will give you a few pointers in the right direction.
If youre still working on it post an update when next you have one and someone will look at it if i dont.
good luck
This post has been edited by hyperionza: 11 Oct, 2007 - 02:03 PM