SearchInt.java - import java.io import java.util.Scanner import java.lang.Integer public class SearchInt public static final String TO_STOP =-1 public

SearchInt.java - import java.io import java.util.Scanner...

This preview shows page 1 - 3 out of 3 pages.

import java.io.*; import java.util.Scanner; import java.lang.Integer; public class SearchInt { public static final String TO_STOP = "-1"; public static final int NOT_FOUND = -1; public static final int MAX_SIZE = 1000; public static int count1; public static int count2; public static int count3; public int sequentialSearch(int[] array, int value) { int low = 0; int high = array.length - 1; for (int i = low; i <= high; i++){ count1++; if (array[i] == value) return i; } return NOT_FOUND; } // end of sequentialSearch() public int sequentialSearch1( int[] list, int item) { int location = -1; for (int i = 0; i < list.length; i++){ if (list[i] == item) location = i; } return location; } public int sequentialSearch2( int[] list, int item) { int location = -1; boolean found = false; for (int i = 0; i < list.length && !found; i++){ if (list[i] == item) { location = i; found = true; } } return location; } public int sequentialSearch3( int[] list, int item) { int index = 0; boolean found = false; while (!found && index < list.length){ if (list[index] == item) found = true; else index++; } return index; }
Image of page 1
public int binarySearch(int[] array, int value) { int low = 0; int high = array.length - 1;
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Spring '14
  • HyukCho
  • public static final int MAX, public static final int, public class SearchInt

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture