순차 정렬




$nom = array(2,3,7,6,5,3,2,2);
$nom2 = array();

//-- 배열을 돌린다.

for($i =0 ; $i < count($nom); $i++){

$chk = 0;

//--- 배열을 다른 배열에 중복되지 않는 값만 담는다.
for($o = 0; $o < count($nom2); $o++){
if($nom2[$o] == $nom[$i]) $chk = 1;
}

if($chk == 0 ) $nom2[$i] = $nom[$i];
echo "$nom[$i]
";

}

echo "-----------------------------
";

//--- 중복값 삭제된 놈

for($i =0 ; $i < count($nom2); $i++){
echo "$nom2[$i]
";
}


echo "-----------------------------
";

//--- 순차정렬


for($i = 0; $i < count($nom2) -1 ; $i++){
$minindex = $i;
$min = $nom2[$i];
for($j = $i + 1; $j < count($nom2); $j++){
if($min > $nom2[$j]){
$min = $nom2[$j];
$minindex = $j;
}
}
$nom2[$minindex] = $nom2[$i];
$nom2[$i] = $min;
}

//--- 최종 정렬된 값

for($i =0 ; $i < count($nom2); $i++){
echo "$nom2[$i]
";
}

?>
크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2004/08/16 10:59 2004/08/16 10:59
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/51

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/51

« Previous : 1 : ... 5788 : 5789 : 5790 : 5791 : 5792 : 5793 : 5794 : 5795 : 5796 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/05   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Statistics Graph

Site Stats

Total hits:
190255
Today:
311
Yesterday:
744