[Nolug] php: list sorting algorithm help

From: Christopher M. Jones <cjones12_at_tulane.edu>
Date: Tue, 23 Dec 2003 23:03:09 -0600
Message-ID: <20031224050309.GA14595@copernicus.tulane.edu>

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?
___________________
Nolug mailing list
nolug@nolug.org
Received on 12/23/03

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