Skip to content

Instantly share code, notes, and snippets.

@OldLipe
Last active May 23, 2018 19:20
Show Gist options
  • Save OldLipe/6073a8da2f10abee7e1f3c87c6f2b073 to your computer and use it in GitHub Desktop.
Save OldLipe/6073a8da2f10abee7e1f3c87c6f2b073 to your computer and use it in GitHub Desktop.
Basic example of bubble sort
#include <stdio.h>
int *ordenador(int lista[],int tamanho){
int i,j,aux;
for (i = 0;i<tamanho;i++){
for (j = 1 + i;j<tamanho;j++){
if (lista[i] > lista[j]){
aux = lista[i];
lista[i] = lista[j];
lista[j] = aux;
}
}
}
return(lista);
}
void mostrar(int *lista){
int tamanho,i;
for (i =0,tamanho = (sizeof(lista)/sizeof(*lista));i<=tamanho;i++){
printf("%d\n",lista[i]);
}
}
int main(void){
int i,number[3],tamanhoLista;
for(i =0;i<3;i++){
scanf("%d",&number[i]);
}
int *lista = ordenador(number,tamanhoLista);
mostrar(lista);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment