我试图让我的searchReturn函数工作,但似乎不能得到它。此外,它说我必须在其他地方调用我的电流,但我不确定如何做到这一点,所以我将其列为私有节点电流;在我代码的开头。我也有问题,试图增加I,以便当它达到我的测试文件中的任何数字时,它返回该节点。
这是我的搜索返回函数:
public class List {
private Node head;
private int length;
private Node current;
//Making the LinkedList, with the head as a new Node
//and the size of the list set to 0
public List(){
length = 0;
}
public boolean isEmptyList(){
if (length == 0){
return true;
}
else{
return false;
}
}
//SearchReturn(L, key): returns a pointer to the Node to the index
public Node searchReturn(int key) {
Node current = head;
while(current != null) {
key++;
}
return current;
}
需要将节点推进到下一个key
次:
public Node searchReturn(int key) {
Node retVal = head;
int i = 0;
while(i < key) {
if (retVal == null) {
return null;
}
retVal = retVal.next();
i++;
}
return retVal;
}