方法实现:

  //1.3.21
/**
* find if some node in the list has key as its item field
*
* @param list the linked list of T
* @param key the T key
*
* @return {@code true} some node exists.
* {@code false} no node exist
*/
public static <T> boolean find(LinkedList<T> list, T key) { for(T s : list) {
if(s.equals(key))
return true;
} return false;
}

测试用例:

package com.qiusongde.linkedlist;

import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut; public class Exercise1321 { public static void main(String[] args) { LinkedList<String> list = new LinkedList<String>(); while(!StdIn.isEmpty()) {
String s = StdIn.readString();
list.insertAtBeginning(s);
StdOut.println("insertAtBeginning success: " + s);
StdOut.println(list);
} String key = "qiu";
StdOut.println("find " + key + " :" + LinkedList.find(list, key)); key = "not";
StdOut.println("find " + key + " :" + LinkedList.find(list, key)); } }

输入数据:

to
be
or
not
to

输出结果:

insertAtBeginning success: to
to
insertAtBeginning success: be
be to
insertAtBeginning success: or
or be to
insertAtBeginning success: not
not or be to
insertAtBeginning success: to
to not or be to
find qiu :false
find not :true

最新文章

  1. NK3C:关于svg文件使用
  2. 使用Vs2012开发Metro时在另一台win8平板上调试的步骤
  3. Windows下好用到必须开机自启的小工具
  4. osharpV3数据库初始化
  5. windows程序是如何开始执行的??
  6. [原创]java WEB学习笔记56:Struts2学习之路---Struts 版本的 登录 demo
  7. HackerRank &quot;Lucky Numbers&quot;
  8. js控制ul的显示隐藏,对象的有效范围
  9. c++继承中的内存布局
  10. Delphi中编辑word
  11. Socket(TCP)客户端请求和服务端监听和链接基础(附例子)
  12. Find Peak Element 解答
  13. vim 括号自动补全
  14. SpringBoot系列: 单元测试2
  15. kindle完结书单
  16. C++面试笔记(2)
  17. 06-HTML-表格标签
  18. vue内置组件 transition 和 keep-alive 使用
  19. Flink--Split和select
  20. geeksforgeeks-Array-Rotation and deletion

热门文章

  1. from: Maven实战(九)——打包的技巧
  2. jQuery ajax 获取信息展示在“下拉列表”中
  3. LM339组成的双限比较器
  4. slam cartographer 学习
  5. 求解复数组 中模较大的N个数
  6. Chrome自带恐龙小游戏的源码研究(六)
  7. Python结合NC.exe 实现模拟登录&amp;批量填表
  8. leetCode 84.Largest Rectangle in Histogram (最大矩形直方图) 解题思路和方法
  9. 畅通project再续 HDU杭电1875 【Kruscal算法 || Prim】
  10. 【WPF学习笔记】之如何点击“新建”按钮,在面板中加载一条条的“用户控件”的信息:动画系列之(四)