Skip to content
Snippets Groups Projects
Commit cfbfe3e0 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

Esboço quick sort interativo

parent 4d902049
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <stdlib.h>
typedef struct EstruturaPilha{
int Posicao;
struct EstruturaPilha *Prox;
} EstruturaPilha;
typedef struct {
EstruturaPilha *Topo;
} TPilha;
void InicPilha (TPilha *Pilha) {
Pilha->Topo = (EstruturaPilha*) malloc (sizeof(EstruturaPilha));
Pilha->Topo->Prox = NULL;
}
int VaziaPilha (TPilha *Pilha) {
return (Pilha->Topo->Prox == NULL);
}
void Push (TPilha *Pilha,int elemento) {
EstruturaPilha *Aux;
Aux = (EstruturaPilha*) malloc (sizeof (EstruturaPilha));
Aux->Prox = Pilha->Topo;
Pilha->Topo->Posicao = elemento;
Pilha->Topo = Aux;
}
void Pop (TPilha *Pilha, int *elemento) {
EstruturaPilha *Aux;
Aux = Pilha->Topo;
Pilha->Topo = Aux->Prox;
free (Aux);
*elemento = Pilha->Topo->Posicao;
}
void QuickSort_Interativo (int *Vetor, int TAM) {
TPilha PilhaDireita, PilhaEsquerda;
int Esquerda, Direita, i, j;
InicPilha (&PilhaDireita);
InicPilha (&PilhaEsquerda);
Esquerda = 0;
Direita = TAM - 1;
Push (&PilhaDireita, Direita);
Push (&PilhaEsquerda, Esquerda);
do {
if (Direita > Esquerda) {
//Particiona (Vetor, Esquerda, Direita, &i, &j);
Push (&PilhaDireita, j);
Push (&PilhaEsquerda, Esquerda);
Esquerda = i;
} else {
Pop (&PilhaDireita, &Direita);
Pop (&PilhaEsquerda, &Esquerda);
}
} while (!VaziaPilha (&PilhaDireita));
}
main() {
int n, TAM;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment