Complete the code to declare a node struct for a binary tree.
typedef struct Node {
int data;
struct Node* [1];
struct Node* right;
} Node;The left child pointer in a binary tree node is typically named left.
Complete the code to access the third element in an integer array named arr.
int value = arr[1];Array indexing in C starts at 0, so the third element is at index 2.
Fix the error in the linked list node insertion code by completing the blank.
new_node->next = [1];
head = new_node;To insert at the beginning, new_node's next should point to the current head.
Fill both blanks to create a function that returns the height of a binary tree.
int height(Node* root) {
if (root == NULL) return 0;
int leftHeight = height(root->[1]);
int rightHeight = height(root->[2]);
return (leftHeight > rightHeight) ? leftHeight + 1 : rightHeight + 1;
}The height function recursively checks the left and right children of the node.
Fill all three blanks to create a function that counts nodes in a linked list.
int countNodes(Node* head) {
int count = 0;
Node* current = head;
while (current != [1]) {
count[2];
current = current->[3];
}
return count;
}The loop runs until current is NULL, increments count, and moves current to next node.
