Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by asdsadasd ( 2 years ago )
#include<stdio.h>
#include<stdlib.h>
#include<locale.h>
#include<stdbool.h> //para utilizar o tipo boleano
void bubble_sort(int vetor[]){
/*colocar o código de ordenação do bubble sort*/
int i,j;
bool houve_troca = false;
int repeticoes = 0;
for (j=8;j>=1;j--){
houve_troca = false;
for (i=0;i<=j;i++){
if (vetor[i]>vetor[i+1]){
int aux = vetor[i];
vetor[i] = vetor[i+1];
vetor[i+1] = aux;
houve_troca = true;
}
repeticoes++;
}
if (!houve_troca){
break;
}
}
printf("\n\nHoveram %d repetições!!!",repeticoes);
}
main(){
int vet[10] = {0,1,2,3,4,5,6,7,8,9};
int i;
setlocale(LC_ALL,"Portuguese");
printf("Cadastre os números no vetor\n\n");
for (i=0;i<=9;i++){
printf("Digite o número para vet[%d] = ",i);
scanf("%d",&vet[i]);
}
printf("\nNúmeros cadastrados SEM ordenação:\n");
for (i=0;i<=9;i++){
printf("%d, ",vet[i]);
}
bubble_sort(vet);
printf("\n\nNúmeros cadastrados ORDENADOS:\n");
for (i=0;i<=9;i++){
printf("%d, ",vet[i]);
}
printf("\n\n");
system("pause");
}
Revise this Paste