0% found this document useful (0 votes)
20 views3 pages

Codigo:: Public Void Int Int Int Int Int Int Do While While If

This document describes the quicksort algorithm for sorting an array. It defines a recursive quicksort method that takes an integer array, and start and end indices. It chooses a pivot element, partitions the array around the pivot by moving all lower elements before it and higher elements after it, and recursively calls itself on the subarrays to complete the sorting. An example run is shown applying the method to sort an sample array.

Uploaded by

Chucho Sanchez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Codigo:: Public Void Int Int Int Int Int Int Do While While If

This document describes the quicksort algorithm for sorting an array. It defines a recursive quicksort method that takes an integer array, and start and end indices. It chooses a pivot element, partitions the array around the pivot by moving all lower elements before it and higher elements after it, and recursively calls itself on the subarrays to complete the sorting. An example run is shown applying the method to sort an sample array.

Uploaded by

Chucho Sanchez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Codigo:

public void ordenarQuicksort(int[]


vector, int primero, int ultimo){
int i=primero, j=ultimo;
int pivote=vector[(primero + ultimo) / 2];
int auxiliar;
do{
while(vector[i]<pivote) i++;
while(vector[j]>pivote) j--;
if (i<=j){
auxiliar=vector[j];
vector[j]=vector[i];
vector[i]=auxiliar;
i++;
j--;
}
} while (i<=j);
if(primero<j) ordenarQuicksort(vector,primero, j);
if(ultimo>i) ordenarQuicksort(vector,i, ultimo);
}

Prueba de escritorio
i<Piv y j>Piv i+1 y j+1
------------------------------------i>Piv i +1
--------------------------------------j<Piv j+1
Arreglo= [22, 40, 4, 10, 12, 35]
Pivote=22
i=40
j=35
------------------------------------------------------Primera vuelta=
[22, 12, 4, 10, 40, 35]
_______________________________
Segunda vuelta=
i=4
j=40
[10, 12, 4, 22, 40, 35]
i, j=10=22
_______________________________
Tercera vuelta=
1=

2=

Piv=10

piv = i,j

i=12

i=40

j=4

j=35

[10, 12, 4] [40, 35]


_______________________________
Cuarta vuelta=
[10, 4, 12] [35,40]
1= i, j= 4

Piv =10
[4, 10, 12][35, 40]
[4, 10, 12, 35, 40]

You might also like