All pastes #2048370 Raw Edit

Miscellany

public text v1 · immutable
#2048370 ·published 2011-04-19 18:40 UTC
rendered paste body
Q: Given an array of data structures that look like:

class MenuItem {
     String Name
     Array<MenuItem> Children
}

write a single method that will output all the MenuItem names and include the level number in front of them:

function PrettyPrint(menuItems, level) {

     foreach(MenuItem item in menuItems) {
        print level + ". " + item.name
        if(item.children)
             PrettyPrint(item.children, level + 1) 
     }
}