<?php
function BubbleSort($numarray)
{
$max = count($numarray);
for ($i = 1; $i < $max;$i++)
{
for ($j = 0; $j < $max - $i; $j++)
{
if ($numarray[$j] > $numarray[$j + 1])
{
$temp = $numarray[$j];
$numarray[$j] = $numarray[$j + 1];
$numarray[$j + 1] = $temp;
}
}
}
return $numarray;
}
function Find_Unique_Elements($numarraya)
{
$numarray=BubbleSort($numarraya);
$count = 0;
$element = $numarray[0];
$result[$count++] = $element;
for ($i = 1; $i < count($numarray); $i++)
{
if ($element == $numarray[$i])
continue;
else
{
$element = $numarray[$i];
$result[$count++] = $element;
}
}
return $result;
}
$array1 = array( 10, 20, 20, 40, 30,25, 30, 35, 40, 45, 50, 55);
$p1 = Find_Unique_Elements($array1);
echo "<br>before Sorted Array <br/>";
for($i=0;$i<count($array1);$i++)
{
echo $array1[$i]." , ";
}
echo "<br>Sorted Unique Array elements from an array <br/>";
for($i=0;$i<count($p1);$i++)
{
echo $p1[$i]." , ";
}
?>
function BubbleSort($numarray)
{
$max = count($numarray);
for ($i = 1; $i < $max;$i++)
{
for ($j = 0; $j < $max - $i; $j++)
{
if ($numarray[$j] > $numarray[$j + 1])
{
$temp = $numarray[$j];
$numarray[$j] = $numarray[$j + 1];
$numarray[$j + 1] = $temp;
}
}
}
return $numarray;
}
function Find_Unique_Elements($numarraya)
{
$numarray=BubbleSort($numarraya);
$count = 0;
$element = $numarray[0];
$result[$count++] = $element;
for ($i = 1; $i < count($numarray); $i++)
{
if ($element == $numarray[$i])
continue;
else
{
$element = $numarray[$i];
$result[$count++] = $element;
}
}
return $result;
}
$array1 = array( 10, 20, 20, 40, 30,25, 30, 35, 40, 45, 50, 55);
$p1 = Find_Unique_Elements($array1);
echo "<br>before Sorted Array <br/>";
for($i=0;$i<count($array1);$i++)
{
echo $array1[$i]." , ";
}
echo "<br>Sorted Unique Array elements from an array <br/>";
for($i=0;$i<count($p1);$i++)
{
echo $p1[$i]." , ";
}
?>
No comments:
Post a Comment