PHP Bubble Sort program File sort_bubble_up.php
- < html>
- < head>< title> php bubble sequencing demo < /title>< head>
- < link rel = "stylesheet" href = "Sort.css" >
- < body>
- < H1> bubble sequencing demo < /h1>
- < table cellpadding = "5" cellspacing ="1"
Border="0" align="center" >
- < ? PHP
- Randomly generated arrays
- $ arr = Array ();
- Echo ' < tr>< td colspan= " ten" class="title">
Initial values < /td>< /tr > ';
- Echo ' < tr>';
- For ($i=0; $i< $i + +) {
- $arr [$i]=rand ();
- echo " < td>$arr [$i]={$arr [$i]}< /td > ";
- }
- To sort by bubbling
- For ($i=9; $i>0; $i-) {
- Echo ' < tr>< td colspan= " ten" class="title"> "
. (10-$i). ' Times < /td>< /tr> ';
- For ($J=0; $j< $i; $j + +) {
- if ($arr [$j]< $arr [$j +1]) {
- $ tmp = $arr [$j];
- $arr [$j]= $arr [$j +1];
- $arr [$j +1]= $tmp;
- }
- Echo ' < tr>';
- for ($k=0; $k< ; $k + +) {
- Switch ($k) {
- Case $j: Echo ' < TD class="base">"; break;
- Case $j +1:echo ' < TD class="Light">";
- Default:echo ' < td>';
- }
- echo "$arr [$k]={$arr [$k]} < /td > ";
- }
- Echo ' < /tr > ';
- }
- }
- Show sort Results
- Echo ' < tr>< td colspan= " ten" class="title"> results < /td >< /tr > ';
- Echo ' < tr>';
- For ($i=0; $i< $i + +) {
- echo " < td>$arr [$i]={$arr [$i]}< /td > ";
- }
- Echo ' < /tr > ';
- ?>
- < /table >
- < /body >< /html >
PHP Bubble Sort style sheet file Sort.css
H1{text-align:center; color:blue;}
table{font-size:12px; font-family:arial; background-color:black; text-align:center;}
Td{background-color:white;}
. Base{background-color: #0FF;}
. Light{background-color: #0DD;}
. Title{background-color: #3FF; text-align:center;}
http://www.bkjia.com/PHPjc/445918.html www.bkjia.com true http://www.bkjia.com/PHPjc/445918.html techarticle php Bubble Sort program file sort_bubble_up.php HTML head title php bubble Sort Method Demo/title head link rel = stylesheet href = sort.css body h1 bubble row Sequencer demo/H1 Table cel ...