我写的查找链表中数据方法
现在我的链表数据为1,1,2,3,都是字符串类型的用方法找“1”,只找到一个,以后的都是null了。
程序代码:
public String[] finddate(String in) {
datenode position = head;
int count = 0;
String[] result = new String[this.countdate()];
int n = 1;
do {
if (position != null) {
while (position.date!=in) {
position = position.next;
}
if (position.date==in)
result[count] = "the location is " + (count+1);
} else
System.out.println("no date at all");
n++;
count++;
position = position.next;
} while (n >= this.countdate());
return result;
}
datenode position = head;
int count = 0;
String[] result = new String[this.countdate()];
int n = 1;
do {
if (position != null) {
while (position.date!=in) {
position = position.next;
}
if (position.date==in)
result[count] = "the location is " + (count+1);
} else
System.out.println("no date at all");
n++;
count++;
position = position.next;
} while (n >= this.countdate());
return result;
}
----------------解决方案--------------------------------------------------------
那个datenode是数据节点,countdate方法是统计链表数据个数的,没错
----------------解决方案--------------------------------------------------------
你这个脑子哪根筋坏了,下面的while写错了,并且还产生了空指针
----------------解决方案--------------------------------------------------------