Advertisement
jounne

hello

Feb 10th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. public static<E> int linearSearch(List<E> list, E element){
  2. for(int i = 0; i < list.size()-1; i++){
  3. if(list.get(i).equals(element)){
  4. return i;
  5. }
  6. }
  7. return -1;
  8. }
  9.  
  10.  
  11. // testet
  12. LinkedList<Integer> lList = new LinkedList<>();
  13. System.out.println("List");
  14. lList.add(17);
  15. for (int i = 0; i < 30; i++) {
  16. lList.add(i, rand.nextInt(100));
  17. }
  18.  
  19. System.out.println(lList);
  20. System.out.println(search.linearSearch(lList, 17));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement