Re: [Nolug] php: list sorting algorithm help

From: Kevin Kreamer <kevin_at_kreamer.org>
Date: Wed, 24 Dec 2003 02:44:34 -0600
Message-Id: <66110E48-35ED-11D8-87C9-00039362B14E@kreamer.org>

Hi,

On Dec 23, 2003, at 23:03, Christopher M. Jones wrote:

> I need an algorithm to sort a list in the following way (in php):
>
> List (unsorted) is as follows:
> 1 / 0
> 2 / 1
> 8 / 1
> 3 / 2
> 7 / 2
> 4 / 3
> 5 / 3
> 6 / 3
> 9 / 8
> 10/ 9
>
> The list should end up like this:
> 1 / 0
> --2 / 1
> ----3 / 2
> ------4 / 3
> ------5 / 3
> ------6 / 3
> ----7 / 2
> --8 / 1
> ----9 / 8
> ------10/ 9
>
> The first field is a unique ID, the second is an association with some
> other entry in the list. This allows topics and subtopics (represented
> above with dashes) of infinite levels to be contained in the same list
> (there are reasons I need this).
>
> I have been struggling with this. I think I am at the limit of my
> programming prowess. Can anybody help, or give me the crucial pointer
> in the right direction?

Here's a solution. Hope this helps.

Kevin

___________________
Nolug mailing list
nolug@nolug.org

Received on 12/24/03

This archive was generated by hypermail 2.2.0 : 12/19/08 EST