Sortieralgorithmen/ Quellcode Quicksort

Aus Wikibooks


<html>
<head>
<title>Quick-sort</title>
</head>
<body>
<script type="text/JavaScript">
function Quicksort(){
if(zahlen.length==0) return[];
var links=[];
var rechts=[];
var pivotelement=zahlen[0];
for(nochzahl=1;nochzahl<zahlen.length;nochzahl++){
zahlen[nochzahl]<pivotelement? links.push(zahlen[nochzahl]) : rechts.push(zahlen[nochzahl]);
}
return Quicksort(links).concat(pivotelement, Quicksort(rechts));
}
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);
Quicksort(zahlen)
document.write(("	Sortiert: ")+zahlen);	
</script>
</body>
</html>