当前位置: 代码迷 >> Java相关 >> 我写的查找链表中数据方法
  详细解决方案

我写的查找链表中数据方法

热度:41   发布时间:2012-12-09 21:38:22.0
我写的查找链表中数据方法
现在我的链表数据为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;
    }
搜索更多相关的解决方案: position  字符串  count  

----------------解决方案--------------------------------------------------------
那个datenode是数据节点,countdate方法是统计链表数据个数的,没错
----------------解决方案--------------------------------------------------------
你这个脑子哪根筋坏了,下面的while写错了,并且还产生了空指针
----------------解决方案--------------------------------------------------------
  相关解决方案