Sortieralgorithmen/ Quellcode Bubblesort

Aus Wikibooks
<html>
<head>
<title>Bubble sort</title>
</head>
<body>
<script type="text/JavaScript">
function Bubblesort(zahlen) {
  var zlänge = zahlen.length - 1;
  do {
    var x = false;
    for(var zia = 0; zia < zlänge; ++zia) {
      if (zahlen[zia] > zahlen[zia+1]) {
        var zz = zahlen[zia];
        zahlen[zia] = zahlen[zia+1];
        zahlen[zia+1] = zz;
        x = true;
      }
    }
  }
  while(x == true)
};
var zahlen = [523,606,387,9 ,592, 670, 684, 65, 362, 296, 685, 531, 714, 244, 76, 477, 11, 544, 497, 134, 432, 156, 968, 469, 317, 61, 423, 309, 208, 993, 831, 789, 802, 69, 376, 10, 428, 288, 814, 879, 263, 506, 48, 990, 659, 16, 23, 695, 194, 45, 447, 930, 555, 592, 543, 665, 290, 912, 467, 835, 405, 844, 683, 568, 247, 820, 797, 119, 618, 124, 468, 736, 462, 87, 119, 888, 899, 618, 42, 236, 727, 453, 437, 732, 525, 977, 791, 807, 993, 978, 262, 679, 669, 580, 690, 785, 800, 554, 839, 380];
document.write(("Unsortiert: ")+zahlen);
Bubblesort(zahlen);
document.write(("	Sortiert: ")+zahlen);
</script>
</body>
</html>