title: Bubble sort of a double array
body: <p>I know the bubble sort algorithm but my question is that what is the efficient code for making this sorting.
  I have two models of this algorithm, I think both make bubble sort correctly but what is the best one of both with respect to memory space and time?!!</p>
  
  <p><strong>Model A:</strong></p>
  
  <pre><code>public static void bubbleSort(double[] array){
      boolean sorted;
      for(int i = 0; i &lt; array.length - 1; i++){
          sorted = true;
          for(int j = array.length - 1; j &gt; i; j--){
              //swap
              if(array[j] &lt; array[j - 1]){
                  double temp = array[j - 1];
                  array[j - 1] = array[j];
                  array[j] = temp;
                  sorted = false;
              }
          }
          if(sorted)
              break;
      }
  }
  </code></pre>
  
  <p><strong>Model B:</strong></p>
  
  <pre><code>static void bubbleSort(double[] list) {
      boolean changed = true;
      do {
          changed = false;
          for (int j = 0; j &lt; list.length - 1; j++)
              if (list[j] &gt; list[j+1]) {
                  //swap list[j] wiht list[j+1]
                  double temp = list[j];
                  list[j] = list[j + 1];
                  list[j + 1] = temp;
                  changed = true;
              }
      } while (changed);
  }
  </code></pre>