clean up quick sort source files
This commit is contained in:
parent
fa78806865
commit
d0b5e27c17
@ -13,22 +13,30 @@
|
||||
* 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) {
|
||||
if(n<2)return;
|
||||
if(n < 2) {
|
||||
return;
|
||||
}
|
||||
int i;
|
||||
int j;
|
||||
int temp;
|
||||
int pivote=array[n/2];
|
||||
for(i=0,j=n-1;;i++,j--){
|
||||
while(array[i] < pivote) i++;
|
||||
while(array[j] > pivote) j--;
|
||||
if(i>=j)break;
|
||||
temp=array[i];
|
||||
int pivote = array[n / 2];
|
||||
for (i =0, j = n - 1;; i++, j--) {
|
||||
while (array[i] < pivote) i++;
|
||||
while (array[j] > pivote) j--;
|
||||
if (i >= j) {
|
||||
break;
|
||||
}
|
||||
temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
array[j] = temp;
|
||||
}
|
||||
|
||||
quick_sort(array,i);
|
||||
quick_sort(array+i,n-i);
|
||||
quick_sort(array, i);
|
||||
quick_sort(array + i, n - i);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user