COMPOUND LITERAL Node* new_top = malloc(sizeof(*new_top)); *new_top = (Node) { .next = NULL, .ch = ch }; // Compound literal └──────┘ └───────────────────────────────┘ Node Node Do not use: - new_top -> next = NULL; - new_top -> ch = ch; Using compound literal helps avoid bugs. D.R.Y. Rule - Don't Repeat Yourself Example: // BEFORE if(*a_top == NULL) { // stack is initially empty *a_top = new_top; } else { // stack is not empty (*a_top) -> next = new_top; // make the existing top refer to the new top *a_top = new_top; // new top becomes the top of the stack } // AFTER if(*a_top != NULL) { // stack is not initially empty (*a_top) -> next = new_top; // make the existing top refer to the new top } *a_top = new_top; // new top becomes the top of the stack } CAUTION: new_top should refer to the old_top, not the other way around. // WRONG (*a_top) -> next = new_top; // make the existing top refer to the new top // RIGHT new_top -> next = *a_top; // make the new top refer to the existing top BOOLEAN VARIABLES / VALUES bool not int true not 1 false not 0 #include at the top RECURSIVE vs. ITERATIVE SOLUTION