
Enviado em 05/11/2020 - 17:45h
Boa noite a todos,int particao(int *v, int ini, int fim, int *r) {
int aux;
int pivo = v[ini];
int i = ini + 1;
int j = fim;
static int troca = 0, comp = 0;
//retorno = malloc(2 * sizeof(int));
while (i <= j)
{
comp++;
while ((i <= j) && v[i] <= pivo) {
i++;
comp++;
}
while(v[j] > pivo) {
j--;
comp++;
}
if (i < j)
{
aux = v[i];
v[i] = v[j];
v[j] = aux;
troca++;
}
}
aux = v[ini];
v[ini] = v[j];
v[j] = aux;
//troca++;
// *c = comp;
// *t = troca;
r[0] = troca;
r[1] = comp;
return j;
} /* Auxiliar para a ordenação por QUICK SORT */
int * quick_sortR(int *v, int ini, int fim) {
int j;
static int *retorno, *r;
static int troca = 0;
static int comp = 0;
retorno = malloc(2 * sizeof(int));
// r = malloc(2 * sizeof(int));
if (ini < fim)
{
comp++;
j = particao(v, ini, fim, r);
if(ini < (j -1)) {
quick_sortR(v, ini, fim);
troca++;
}
if((j+1) < fim) {
quick_sortR(v, j + 1, fim);
troca++;
}
}
retorno[0] = r[0];
retorno[1] = r[1];
// free(r);
return retorno;
}
/* Ordenação por QUICK SORT */
void quick_sort(int *v, int tam, int tipo_v) {
int *r;
// FILE *arq;
r = quick_sortR(v, 0, tam -1);
//quick_sortR(v, 0, tam -1);
printf("\nTrocas: %d Comparações: %d\n", r[0], r[1]);
}
void gera_vetor(int *v, int n, int tipo) {
int i = 0;
if (tipo == 1)
{
srand(time(NULL));
for (i = 0; i < v10; i++)
v[i] = rand() % 10;
}
if (tipo == 2)
{
for (i = 0; i < n; i++)
v[i] = i;
}
if(tipo == 3)
for (i = 0; i < n; i++)
v[i] = n - i - 1;
} #include <stdio.h>
#include <stdlib.h>
int main() {
// int i;
int *vd;
// int *vc;
// int *vm;
// int tam = v10;
vd = malloc(v10 * sizeof(int));
// vc = malloc(v100 * sizeof(int));
// vm = malloc(v1000 * sizeof(int));
printf("\n");
gera_vetor(vd, 10, 1);
for (int i = 0; i < 10; i++)
printf("%d ", vd[i]);
quick_sort(vd, 10, 1);
printf("\n");
for (int i = 0; i < 10; i++)
printf("%d ", vd[i]);
printf("\n");
printf("\n");
free(vd);
// free(vc);
// free(vm);
return 0;
}
KDE Plasma - porque pode ser a melhor opção de interface gráfica
Gentoo: detectando impressoras de rede e como fixar uma impressora por IP
Como o GNOME conseguiu o feito de ser preterido por outras interfaces gráficas
Por que sua empresa precisa de uma PKI (e como automatizar EMISSÕES de certificados via Web API)
Instalando NoMachine no Gentoo com Systemd (acesso Remoto em LAN)
Instalar Linux em notebook Sony Vaio VPCEG13EB (13)
Vou destruir sua infância:) (7)
Interface gráfica com problema (0)









