title: Using the Binary Search method to find the index of an Item
body: <p>So I am to rewrite two functions from using sequential search to binary search. I'm understanding the difference in efficiency between the two, however, I'm having trouble with the syntax while changing them to binary.</p>
  
  <p><strong>Class</strong></p>
  
  <pre><code>public class SortedList&lt;Item extends Comparable&lt;Item&gt;&gt; implements SortedList&lt;Item&gt; {
  
      private Object[] data = new Object[5];
  
      private int size = 0;
  
      public int size() {
          return size;
      }
  
      public boolean isEmpty() {
          return size == 0;
      }
  
      public boolean equals(Object o) {
          SortedList&lt;Item&gt; lst = (SortedList&lt;Item&gt;) o;
          if (size != lst.size)
              return false;
          Iterator&lt;Item&gt; i1 = lst.iterator();
          Iterator&lt;Item&gt; i2 = iterator();
          while (i1.hasNext()) {
              Item x1 = i1.next();
              Item x2 = i2.next();
              if (!x1.equals(x2))
                  return false;
          }
          return true;
      }
  
      //METHOD TO CHANGE TO BINARY-SEARCH
      public int indexOf(Item x) {
           int low = 0, high = size - 1;
           while (low &lt;= high) {
              int mid = (low + high) / 2;
              if ((int) x == mid)
                  return mid;
              else if ((int) x &gt; mid)
                  high = mid - 1;
              else
                  low = mid + 1;
          }
          return -1;
       }
  </code></pre>
  
  <p><strong>Main</strong></p>
  
  <pre><code>public class Main {
  
      public static void main(String[] args) {
  
          SortedList&lt;Integer&gt; s = new SortedList&lt;Integer&gt;();
  
          s.add(5);
          s.add(6);
          s.add(7);
          s.add(8);
          s.add(9);
          s.add(10);
  
          System.out.println(s.indexOf(6)); //-1
  
      }
  }
  </code></pre>
  
  <p>Basically, I'm having trouble comparing the <code>Item x</code> with integers. It seems that even when I cast <code>x</code> to and <code>Int</code> the function still returns <code>-1</code>. What is the correct way for me to compare in this function? I can also provide more of the code if necessary, I included all I thought was relevant.</p>