Skip to content

Instantly share code, notes, and snippets.

@kdrnic
Created February 5, 2022 22:02
Show Gist options
  • Save kdrnic/0d121011fe1bdc32f489a24e58cc61ae to your computer and use it in GitHub Desktop.
Save kdrnic/0d121011fe1bdc32f489a24e58cc61ae to your computer and use it in GitHub Desktop.
/*
allocate a child and move down
parent -> null
^
to
parent -> new child
^
*/
void typ_recur(struct typ **typ)
{
(*typ)->child = typ_alloc();
*typ = (*typ)->child;
}
/*
allocate a child and move down
parent -> old child
^
to
parent -> new child -> old child
^
*/
void typ_recur2(struct typ **typ)
{
struct typ *child = (*typ)->child;
(*typ)->child = typ_alloc();
(*typ)->child->child = child;
*typ = (*typ)->child;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment