ggmufc
BAN USER/*
* create a mirrored tree
*/
tree_node_t* tree_create_mirror (tree_node_t* root)
{
if (root == NULL) {
return (NULL);
}
tree_node_t *new_root = (tree_node_t*)malloc(sizeof(tree_node_t));
if (new_root == NULL) {
printf("tree node malloc failure.\n");
return (NULL);
}
new_root->value = root->value;
new_root->left = tree_create_mirror(root->right);
new_root->right = tree_create_mirror(root->left);
return (new_root);
}
The function requires the number of nodes in the singly linked list.
int linklist_is_palindrome (singly_node_t *head, int n, singly_node_t **end)
{
if (n == 1) {
*end = head;
return (1);
}
if (n == 2) {
*end = head->next;
return (head->value == (*end)->value);
}
singly_node_t *last;
if (!linklist_is_palindrome(head->next, n-2, &last)) {
return (0);
}
*end = last->next;
return (head->value == (*end)->value);
}
If we assume the robot can only move down and to its right.
- ggmufc August 12, 2013