Skip to content

Instantly share code, notes, and snippets.

@salluzziluca
Last active July 7, 2022 12:50
Show Gist options
  • Save salluzziluca/18cbfe06f35192e04c8d52d6870de149 to your computer and use it in GitHub Desktop.
Save salluzziluca/18cbfe06f35192e04c8d52d6870de149 to your computer and use it in GitHub Desktop.
Bubble Sort
void bubble_sort(char vector_desordenado[MAX_VECTOR], char vector_ordenado[MAX_VECTOR], int tope, bool ascendente){
int j, i;
for(i = 0; i < tope; i++){
for(j = 0; j < tope-1; j++){
if(ascendente){
if(vector_desordenado[j] > vector_desordenado[j+1]){
char aux = vector_desordenado[j];
vector_desordenado[j] = vector_desordenado[j+1];
vector_desordenado[j+1] = aux;
}
}
else{
if(vector_desordenado[j] < vector_desordenado[j+1]){
char aux = vector_desordenado[j];
vector_desordenado[j] = vector_desordenado[j+1];
vector_desordenado[j+1] = aux;
}
}
}
}
for(i = 0; i < tope; i++){
vector_ordenado[i] = vector_desordenado[i];
}
}
def burbujeo(lista):
largo = len(lista)
while i > largo and intercambio:
intercambio = False
for j in range(0, largo-i-1):
if lista[j] > lista[j+1]:
lista[j], lista[j+1] = lista[j+1], lista[j]
intercambio = True
return lista
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment