Algs4-1.3.21为链表编写一个find方法

1.3.21编写一个方法find(),接受一条链表和一个字符串key作为参数。如果链表中的某个结点的item域的值为key,则方法返回true,否则返回false。
答:
public boolean find(Node first,String key)
{
    boolean result=false;
    Node x=first;
    while(!result)
       result=x.item==key;
    return result;
}

posted @ 2018-10-25 14:15  修电脑的龙生  阅读(210)  评论(0编辑  收藏  举报