Re: PHP sort from .... best solution?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi again!

I talked to the admin guy and he said there is an easyer way to do this (as
usual he doenst have the time to show me) so I try here:

He gave me a liddle example in c and a light translation to PHP:

Bubble sort  (exampel written in c, but can "easyly" be translated to php):
for (i=0; i<n-1; i++) {
  for (j=0; j<n-1-i; j++)
    if (a[j+1] < a[j]) {  /* compare the two neighbors */
      tmp = a[j];         /* swap a[j] and a[j+1]      */
      a[j] = a[j+1];
      a[j+1] = tmp;
  }
}

**************

More example of Bubble Sort:
http://www.cs.ust.hk/faculty/tcpong/cs102/summer96/aids/bubble.html

The if-sentense must here be written to
if($a[$j+1]->publisertLang < $a[$j]->publisertLang)
where a is $ingresser and $n is the number of elements in $ingresser.

I

The if sentese is going in the php file pastet yesterday.

Not that yeasterdays metod did'nt work, but if somebody has an idea on this
one and can give me a full example based on the info i've pastet yesterday
it would be great!

Regards,
A. Lyse



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux