递归顺序搜索Java代码 [英] recursive seqeuntial search java code

查看:81
本文介绍了递归顺序搜索Java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   int  seqSearch(T []列表, int 长度,T searchItem)
{
     int  loc;
    boolean found =  false ;
     for (loc =  0 ; loc< length; loc ++)
    {
        如果(列表[loc] .equals(searchItem))
        {
           found =  true ;
            break ;
        }
    }

    如果(找到)
        返回 loc;
    其他
        返回- 1 ;
} 

解决方案

我们不做作业:它的设置是有原因的.在这里,您可以考虑自己被告知的内容,并尝试理解它.也可以在那里帮助您的导师识别您的弱点,并将更多的注意力放在补救措施上.

自己尝试,您可能会发现它并不像您想的那么难!

您可能还希望与班上的其他同学聚会-其中之一是在这里:递归顺序搜索 [ ^ ]

public int seqSearch(T[] list, int length, T searchItem)
{
    int loc; 
    boolean found = false;
    for(loc = 0; loc < length; loc++)
    {
        if(list[loc].equals(searchItem))
        {
           found = true;
           break; 
        }
    }

    if(found)
        return loc;
    else
        return-1;
}

解决方案

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

You might also want to get together with the rest of your class - one of them is here: recursive sequential search[^]


这篇关于递归顺序搜索Java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆