diff options
Diffstat (limited to 'leetcode.c')
-rw-r--r-- | leetcode.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/leetcode.c b/leetcode.c new file mode 100644 index 0000000..66d2064 --- /dev/null +++ b/leetcode.c @@ -0,0 +1,33 @@ +#include "leetcode.h" + +struct ListNode *listnode_create(int val) { + struct ListNode *new = (struct ListNode *)malloc(sizeof(struct ListNode)); + new->val = val; + new->next = NULL; + return new; +} + +void listnode_print(struct ListNode *head) { + struct ListNode *curr = head; + while (curr != NULL) { + printf("%d ", curr->val); + curr = curr->next; + } + printf("\n"); +} + +struct TreeNode *treenode_create(int val) { + struct TreeNode *new = (struct TreeNode *)malloc(sizeof(struct TreeNode)); + new->val = val; + new->left = NULL; + new->right = NULL; + return new; +} + +void treenode_print(struct TreeNode *root) { + if (!root) + return; + treenode_print(root->left); + printf("%d ", root->val); + treenode_print(root->right); +} |