Merge branch 'cleanquicksort' of UBB/sort into master

This commit is contained in:
Chris Cromer 2018-11-14 20:12:12 -03:00 committed by Gitea
commit 0f6c3f3b53

View File

@ -13,8 +13,15 @@
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/**
* Usar el algoritmo de quick sort
* @param array El array a ordenar
* @param n El tamaño del array
*/
void quick_sort(int *array, int n) { void quick_sort(int *array, int n) {
if(n<2)return; if(n < 2) {
return;
}
int i; int i;
int j; int j;
int temp; int temp;
@ -22,7 +29,9 @@ void quick_sort(int *array, int n) {
for (i =0, j = n - 1;; i++, j--) { for (i =0, j = n - 1;; i++, j--) {
while (array[i] < pivote) i++; while (array[i] < pivote) i++;
while (array[j] > pivote) j--; while (array[j] > pivote) j--;
if(i>=j)break; if (i >= j) {
break;
}
temp = array[i]; temp = array[i];
array[i] = array[j]; array[i] = array[j];
array[j] = temp; array[j] = temp;
@ -31,4 +40,3 @@ void quick_sort(int *array, int n) {
quick_sort(array, i); quick_sort(array, i);
quick_sort(array + i, n - i); quick_sort(array + i, n - i);
} }