/* --- Function: static void destroy_right(AvlTree tree, AvlTreeNode node) --- */ static void destroy_right(AvlTree tree, AvlTreeNode node) { AvlTreeNode *position; /* Destruction of an empty tree is not allowed.. */ if (tree->size == 0) return; /* Determine where to destroy nodes... */ if (node == NULL) position = &tree->root; else position = &node->right; /* Destroy the nodes... */ if (*position != NULL) { destroy_left(tree, *position); destroy_right(tree, *position); if (tree->destroy != NULL) { /* Call a user-defined function to free dynamically allocated data */ tree->destroy((*position)->data); } /* Now, free the node itself... */ free(*position); *position = NULL; /* Adjust the size of the tree to account for the destroyed node... */ tree->size--; } }
__task void stop_block(void *void_ptr) { while(1) { os_sem_wait(&next_block, 0xffff); watchdog_timer = os_time_get(); x_offsets[count] = current_block.x_offset; if(count != 0){ diff = x_offsets[count] - x_offsets[count - 1]; // If the block completely missed the stack, game over if (abs(diff) >= current_block.width - 1 ){ GLCD_DisplayString(1, 1, 1, " GAME OVER "); os_sem_wait(&next_block, 0xffff); reset(); continue; } // If the block extends to the right of the stack else if(diff < 0){ destroy_left(); x_offsets[count] -= diff; current_block.width += diff; } // If the block extends to the left of the stack else if (diff > 0){ destroy_right(); current_block.width -= diff; } // If the block is perfectly stacked, do nothing } current_block.y_offset -= HEIGHT; current_block.x_offset = INITIAL_X; current_block.color++; widths[count] = current_block.width; count++; } }
static void destroy_right (BisTree *tree, BiTreeNode *node) { BiTreeNode **position; /* Do not allow destruction of an empty tree. */ if (bitree_size (tree) == 0) return; /* Determine where to destroy nodes. */ if (node == NULL) position = &tree->root; else position = &node->right; /* Destroy the nodes. */ if (*position != NULL) { destroy_left (tree, *position); destroy_right (tree, *position); if (tree->destroy != NULL) { /* Call a user-defined function to free dynamically allocated data. */ tree->destroy (((AvlNode *) (*position)->data)->data); } /* Free the AVL data in the node, then free the node itself. */ free ((*position)->data); free (*position); *position = NULL; /* Adjust the size of the tree to account for the destroyed node. */ tree->size--; } return; }