//================================================================
// Nome Do Arquivo: bubble.cpp
// File Name: bubble.cpp
//
// Includes: stdio.h
//
// Descrição: Implementação do algoritmo de ordenação por seleção
// Description: Bubble Sort Algorithm
//================================================================
// Define uma constante
// Define a constant
#define MAX 10
// Protótipo da função de ordenação
// Ordination function prototype
void bubble_sort(int *a);
// Função main
// Main Function
int main(int argc, char** argv)
{
int i, vet[MAX];
// Lê MAX ou 10 valores
// Read MAX or 10 values
for(i = 0; i < MAX; i++)
{
printf("Digite um valor: ");
scanf("%d", &vet[i]);
}
// Ordena os valores
// Order values
bubble_sort(vet);
// Imprime os valores ordenados
// Print values in order ascendant
printf("nnValores ordenadosn");
for(i = 0; i < MAX; i++)
{
printf("%dn", vet[i]);
}
return 0;
}
// Função de ordenação bolha
// Bubble sort function
void bubble_sort(int *a)
{
int i, j, tmp;
for(i = 0; i < MAX; i++)
{
for(j = i+1; j < MAX; j++)
{
if(a[j] < a[i])
{
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
}
}
}
Algoritmo de Ordenação Bolha em C (Bubble Sort)
Deixe um comentário