/*
 * Copyright (C) 2014 Pedro Vicente Gómez Sánchez.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.pedrovgs.problem74;

/**
 * Given an array full of integers implement a bubble sort algorithm to sort the content inside the
 * array.
 *
 * @author Pedro Vicente Gómez Sánchez.
 */
public class BubbleSort {

}

@@ -833,10 +833,1724 @@
 Sort %7B%0A%0A
+  /**%0A   * Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that%0A   * repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps%0A   * them if they are in the wrong order. The pass through the list is repeated until no swaps are%0A   * needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is%0A   * named for the way smaller elements %22bubble%22 to the top of the list. Although the algorithm is%0A   * simple, it is too slow and impractical for most problems even when compared to insertion%0A   * sort. It can be practical if the input is usually in sort order but may occasionally have%0A   * some out-of-order elements nearly in position.%0A   *%0A   * The complexity order of this algorithm in time terms is O(N%5E2) where N is equals to the number%0A   * of elements in the input array. In space terms, the complexity order is O(1) because to solve%0A   * this problem we are not using any auxiliary data structure.%0A   */%0A  public void sort(int%5B%5D numbers) %7B%0A    validateInput(numbers);%0A%0A    int length = numbers.length;%0A    boolean swap = true;%0A    while (swap) %7B%0A      swap = false;%0A      for (int i = 0; i %3C length - 1; i++) %7B%0A        for (int j = i + 1; j %3C length; j++) %7B%0A          if (numbers%5Bi%5D %3E numbers%5Bj%5D) %7B%0A            swap(numbers, i, j);%0A            swap = true;%0A          %7D%0A        %7D%0A      %7D%0A    %7D%0A  %7D%0A%0A  private void swap(int%5B%5D numbers, int i, int j) %7B%0A    int temp = numbers%5Bi%5D;%0A    numbers%5Bi%5D = numbers%5Bj%5D;%0A    numbers%5Bj%5D = temp;%0A  %7D%0A%0A  private void validateInput(int%5B%5D numbers) %7B%0A    if (numbers == null) %7B%0A      throw new IllegalArgumentException(%22You can't pass a null instance as parameter.%22);%0A    %7D%0A  %7D%0A
 %7D%0A

Add solution to problem 74