| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 402 人关注过本帖
标题:我写的查找链表中数据方法
只看楼主 加入收藏
回转逆流
Rank: 1
等 级:新手上路
帖 子:8
专家分:8
注 册:2012-11-17
收藏
 问题点数:0 回复次数:2 
我写的查找链表中数据方法
现在我的链表数据为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 
2012-12-09 21:38
回转逆流
Rank: 1
等 级:新手上路
帖 子:8
专家分:8
注 册:2012-11-17
收藏
得分:0 
那个datenode是数据节点,countdate方法是统计链表数据个数的,没错
2012-12-09 21:40
回转逆流
Rank: 1
等 级:新手上路
帖 子:8
专家分:8
注 册:2012-11-17
收藏
得分:0 
你这个脑子哪根筋坏了,下面的while写错了,并且还产生了空指针
2012-12-09 21:50
快速回复:我写的查找链表中数据方法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014425 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved