Skip to content

Instantly share code, notes, and snippets.

@Bolinha1
Last active July 15, 2016 19:34
Show Gist options
  • Select an option

  • Save Bolinha1/10787377 to your computer and use it in GitHub Desktop.

Select an option

Save Bolinha1/10787377 to your computer and use it in GitHub Desktop.
método de ordenação bolha (bubble sort) em PHP
<?php
function bubbleSort($array)
{
for($i = 0; $i < count($array); $i++)
{
for($j = 0; $j < count($array) - 1; $j++)
{
if($array[$j] > $array[$j + 1])
{
$aux = $array[$j];
$array[$j] = $array[$j + 1];
$array[$j + 1] = $aux;
}
}
}
}
$arr = array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
return var_dump(bubbleSort($arr)); // saída array[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
@dritux
Copy link

dritux commented Mar 10, 2016

Falta um return não?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment