In this layout we now unconditionally heap allocate our nodes. The key difference is the absence of the junk from our first layout. What is this junk? To understand that, we'll need to look at how an enum is laid out in memory.
i'm not entirely sure why the node representation for Elem B has a *null*; given that the nodes are required to have a pointer to a List, shouldn't it be (Elem B, ptr) -> (Empty, junk)?
Problem
[ptr] -> (Elem A, ptr) -> (Elem B, *null*)
i'm not entirely sure why the node representation for
Elem B
has a*null*
; given that the nodes are required to have a pointer to aList
, shouldn't it be(Elem B, ptr) -> (Empty, junk)
?