You need to print out "|" whenever on the corresponding level you are not processing the last entry, but one of the entries before the last. You need to know this for every level separately, so you could add a bit mask or a string (say) as an extra argument to 'getInto'.