title: finding minimal difference
body: <p>I have an array A=[a1,a2,a3,a4,a5...] and I want to find two elements of the array, say A[i] and A[j] such that i is less than j and A[j]-A[i] is minimal. </p>
  
  <p>Would this code do the job:</p>
  
  <pre><code>def findMinDifference(A):
      Unsorted=[]
      minDiff=1000000
      Unsorted=A
      Sorted=quickSort(A)
      for i in range(0,len(Sorted)):
          if i&gt;=1:
           SmallElement=Sorted[i-1]
           indexOfSmaller=Unsorted.index(SmallElement)
           BigElement=Sorted[i]
           indexOfBig=Unsorted.index(BigElement)
          if indexOfSmaller&lt;inexOfBig:
               diff=Sorted[i]-Sorted[i-1]
               if diff&lt;minDiff:
                   minDiff=diff
      return minDiff
  </code></pre>