# Plotting Nested Lists

How to plot a linked list such as:

ll = {{a, b}, {{c, d}, {{e, f}, {}}}}


The expected result is a tree with the nodes and edges ordered as follows.

The empty / null nodes should not be displayed. The starting node can have a root label or a user defined label.

• Sounds like you could do most of this with TreeForm if you use the right option settings. – Sjoerd Smit Dec 24 '18 at 10:52
• As Sjoerd Smit sayd, TreeForm@list is almost that what you want... and a bit more, the empty list is displayed correctly – mgamer Dec 24 '18 at 12:15
• Thanks @SjoerdSmit the answer uses exactly that ! I've accepted this as a correct solution. – v1j4y Dec 24 '18 at 14:28

As recommended in the comments, use TreeForm

\$Version

(* "11.3.0 for Mac OS X x86 (64-bit) (March 7, 2018)" *)

ll = {{a, b}, {{c, d}, {{e, f}, {}}}};

TreeForm["root" @@ (ll /. {} :> Nothing),
VertexRenderingFunction -> (Text[
If[#2 === List, "",
Framed[Style[#2, 18], Background -> White,
FrameStyle -> White]], #1] &)]


• That's exactly what I was looking for ! Brilliant. – v1j4y Dec 24 '18 at 14:23
• Perhaps this tweak is useful: tf[ex_, root_: "root"] := TreeForm[root @@ (ex /. {} :> Nothing), VertexRenderingFunction -> (Text[ If[#2 === List, "", Style[#2, 18]], #1] &)]; – Somos Dec 24 '18 at 19:16