ianbrind 0 Report post Posted January 28, 2009 (edited) Hi,Today I went about creating an ideal bubble sort algorithm.I came up with this: $this->flag = true; if($this->p==true) $this->returned .= ''; for($i = 1; $i < $num; ++$i){ if($this->p==true){ if($i==$num-1) $c = 'style="border linenums:0'>Class Bubble{ function Sort($array, $num, $process = false){ $this->p = $process; $this->returned = ''; $this->flag = true; if($this->p==true) $this->returned .= ''; for($i = 1; $i < $num; ++$i){ if($this->p==true){ if($i==$num-1) $c = 'style="border:eeee88; background:#ffff88;"'; else $c=''; $this->returned .= 'AAAAAA'; } for($x = 1; $x < $num; ++$x){ if($array[$i] < $array[$x]){ $hold = $array[$i]; $array[$i] = $array[$x]; $array[$x] = $hold; } if($this->p==true) $this->returned .= 'AAA'; } } if($this->p==true) $this->returned .= 'AAAAAABBBSort '.$i.''.$array[$x].''; if($this->p==true) return $this->returned; else return $array; }}$ns = $B->Sort($n, $n1, true); // $n is array (1,2,5,9,11,52,27), $n1 is array size echo $ns; The output of $ns display the individual steps in the sorting algorithm but it doesn't look like a conventional bubble sort table.I think there may be a logic error in my for loops.(AAA/BBB are table tags)Any thoughts?Thanks Edited January 28, 2009 by ianbrind (see edit history) Share this post Link to post Share on other sites
ragav.bpl 0 Report post Posted January 29, 2009 Hi,Today I went about creating an ideal bubble sort algorithm.I came up with this: $this->flag = true; if($this->p==true) $this->returned .= ''; for($i = 1; $i < $num; ++$i){ if($this->p==true){ if($i==$num-1) $c = 'style="border linenums:0'>Class Bubble{ function Sort($array, $num, $process = false){ $this->p = $process; $this->returned = ''; $this->flag = true; if($this->p==true) $this->returned .= ''; for($i = 1; $i < $num; ++$i){ if($this->p==true){ if($i==$num-1) $c = 'style="border:eeee88; background:#ffff88;"'; else $c=''; $this->returned .= 'AAAAAA'; } for($x = 1; $x < $num; ++$x){ if($array[$i] < $array[$x]){ $hold = $array[$i]; $array[$i] = $array[$x]; $array[$x] = $hold; } if($this->p==true) $this->returned .= 'AAA'; } } if($this->p==true) $this->returned .= 'AAAAAABBBSort '.$i.''.$array[$x].''; if($this->p==true) return $this->returned; else return $array; }}$ns = $B->Sort($n, $n1, true); // $n is array (1,2,5,9,11,52,27), $n1 is array size echo $ns; The output of $ns display the individual steps in the sorting algorithm but it doesn't look like a conventional bubble sort table.I think there may be a logic error in my for loops.(AAA/BBB are table tags)Any thoughts?Thanks Nice program matebut how to run it mate ........ Share this post Link to post Share on other sites