0
I have this code below working correctly.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void quicksort (int *vetor, int inicio, int fim) {
int i, j, meio, aux;
i = inicio;
j = fim;
meio = vetor [(inicio+fim)/2];
do {
while (vetor [i] < meio)
i++;
while (vetor [j] > meio)
j--;
if (i<= j) {
aux = vetor[i];
vetor[i] = vetor[j];
vetor[j] = aux;
i++;
j--;
}
} while (i <= j);
if (inicio < j)
quicksort(vetor, inicio, j);
if (i < fim)
quicksort(vetor, i, fim);
}
int main()
{
int vetor[8] = {25, 57, 48, 37, 12, 92, 86, 33};
int n = 8, i;
quicksort(vetor,0,n-1);
for (i=0; i<8; i++) {
printf("%d ", vetor[i]);
}
return 0;
}
1 - I determine the middle of the vector and this means will be the pivot, which in my accounts is at position 3, content 37.
From there what the next step?
This might help you: https://youtu.be/ywWBy6J5gz8
– Woss
Animations: wikipedia, tutorialspoint, Wikimedia.
– Lacobus