Пример #1
0
/* --- 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--;
    }
}
Пример #2
0
void
bistree_destroy (BisTree *tree)
{
  /* Destroy all nodes in the tree.  */
  destroy_left (tree, NULL);

  /* No operations are allowed now, but clear the structure as a precaution.  */
  memset (tree, 0, sizeof(BisTree));
  return;
}
Пример #3
0
__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++;
	}
}	
Пример #4
0
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;
}
Пример #5
0
void AVLTREEdestroy(AvlTree tree)
{
  destroy_left(tree, NULL);
  free(tree);
}