Pushing a char into a quack:
char bigA = 'A'; push((int)bigA, play); // cast the char to an int before pushing |
Popping a char from a quack:
char c; c = (char)pop(play); // cast the int to a char after popping |
free node 1 free node 2 free node 3 free node 4 |
void freeList(NodeT *cur) { if (cur != NULL) { NodeT *temp; temp = cur->next; printf("free node %d\n", cur->data); free(cur); freeList(temp); } } |
free node 1 free node 2 free node 3 free node 4 |
A function to recursively free nodes, in backward direction:
void freeList(NodeT *cur) { if (cur != NULL) { freeList(cur->next); printf("free node %d\n", cur->data); free(cur); } } |
free node 4 free node 3 free node 2 free node 1 |
free(cur); freeList('cur->next'); |
freeList(cur->next); free(cur); |
Freeing a tree in postfix order is the only way to do it.
void freeTree(Tree t) { // free all memory associated with the tree if (t != NULL) { freeTree(t->left); // must free the children first freeTree(t->right); free(t); } } |
In essence:
sumTree() will need to return the current sum as you move up the tree
sumTree(t) = 0 if t == NULL = t->data + sumTree(t->left) + sumTree(t->right) otherwise |