PHP bubble sort program file sort_bubble_up.php
- < html>
-
< head>< title>PHP bubble sort demonstration< /title>< head>
-
< link rel="stylesheet" href="sort.css">
-
< body>
-
< h1>Bubble sorting demonstration< /h1>
-
< table cellpadding="5" cellspacing="1"
border="0" align="center">
-
< ?php
- //Randomly generate array
- $arr=array();
- echo '< tr>< td colspan ="10" class="title">
Initial value< /td>< /tr>'; 🎜>
tr-
>'; for($i=0
;$i-
< 10;$i++){ $arr[$i]=rand(); echo "<
td- >$arr[$i]={$arr [$i]}< /td> "; } //Perform bubble sorting for($i
- =
- 9
;$i -
>0;$i--){ echo '<
tr- >< td colspan ="10" class ="title">th'.(10-$i).'次< /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< 10;$k++){
- switch($k){
- case $j : echo '< td class="base">'; break;
-
case $j+1 : echo '< td class="light">'; break;
-
default : echo '< td>';
- }
-
echo "$arr[$k]={$arr[$k]}< /td>";
- }
-
echo '< /tr>';
- }
- }
- //Display sorting results
-
echo '< tr>< td colspan="10" class="title">Result< /td>< /tr>'; 🎜>
-
tr>'; for($i=
- 0;$i < 10;$i++){ echo "<
- td>$arr[$i]={$arr[$i]} < /td>"; } echo '
<-
/tr- >'; >
- <
- /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.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445918.html
TechArticle
PHP bubble sort program file sort_bubble_up.php html head title PHP bubble sort method demonstration/title head link rel = stylesheet href = sort.css body h1 bubble sort method demonstration/h1 table cel...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn