Sortieralgorithmen/ Quellcode Selectionsort

Aus Wikibooks


<html>
<head>
<title>Selection-sort</title>
</head>
<body>
<script type="text/JavaScript">
function Selectionsort(zahlen){
for (var nochzahl=0;nochzahl<zahlen.length-1;nochzahl++){
var zz=nochzahl;
for(var zia=nochzahl+1;zia < zahlen.length;zia++){
if (zahlen[zia]<zahlen[zz]){
zz=zia;
}
	}
	if (zz !=nochzahl){
var zz2=zahlen[zz];
zahlen[zz]=zahlen[nochzahl];
zahlen[nochzahl]=zz2;
}
	}
		}
 
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);
Selectionsort(zahlen);
document.write(("	Sortiert: ")+zahlen);
		
</script>
</body>
</html>