Hi all,

I have a 3-tier menu system in that there are 3 levels such that each top-level menu item has X mid-level items and each mid-level item has Y bottom-level items.

For each top-level item I need to split the mid-level and bottom-level items into 3 columns as equally as possible with the restriction that I cannot split the children of a mid-level item into 2+ columns. If I didn't have to keep all the children of a mid-level item together, making equal columns would be pretty much as simple as diving the total number of children in a top level item by 3. However, since I need to group the children of all mid-level items, this seems to become less trivial.

For example - 3 columns of equal length:

| Mid 1       | Mid 2       | Mid 3       |
| -Bottom 1-1 | -Bottom 2-1 | -Bottom 3-1 |
| -Bottom 1-2 | -Bottom 2-2 | -Bottom 3-2 |
| -Bottom 1-3 | -Bottom 2-3 | -Bottom 3-3 |
| -Bottom 1-4 | -Bottom 2-4 | -Bottom 3-4 |

And 3 unequal columns:

| Mid 1       | Mid 2       | Mid 4       |
| -Bottom 1-1 | -Bottom 2-1 | -Bottom 4-1 |
| -Bottom 1-2 | Mid 3       | -Bottom 4-2 |
| -Bottom 1-3 | -Bottom 3-1 | -Bottom 4-3 |
| -Bottom 1-4 | -Bottom 3-1 |             |

I'm not looking for code, I'm just looking for an idea on how to approach this conceptually.

assuming the order of the columns matters

//get maxHeight from the columns + 1 for the header (mid)
maxHeight = count(biggest) + 1
loop menuItems
    //curHeight needs to include all mid and bottom already printed
    if curHeight + nextColLength + 1 > maxHeight
        nextCol
    else
        printCol

if the order doesn't matter then you need to sort through the columns and match them up so they fit the best

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.