Exemple #1
0
rtems_task Init(
  rtems_task_argument argument
)
{
  puts( "\n\n*** TEST 70 ***" );

  create_helper( 1 );
  create_helper( 2 );
  create_helper( 3 );
  create_helper( 4 );
  create_helper( 5 );
  create_helper( 6 );

  delete_helper( 2 );
  delete_helper( 3 );
  delete_helper( 4 );
  delete_helper( 5 );

  create_helper( 2 );
  create_helper( 3 );
  create_helper( 4 );
  create_helper( 5 );

  puts( "*** END OF TEST 70 ***" );

  rtems_test_exit(0);
}
Exemple #2
0
/**
 * Funkcja pomocnicza dictionary_delete.
 * Usuwa węzły reprezentujące slowo 'word' w słowniku 'dict'.
 * @param[in,out] dict Słownik.
 * @param[in] prev Wskaźnik na ojca. Jeśli 'dict' to root należy wstawić NULL.
 * @param[in] word Usuwane słowo.
 * @return 0 jeśli 'prev' po usunięciu węzła nie posiada już dzieci, 1 w p.p.
 */
static int delete_helper(struct dictionary *dict, struct dictionary *prev,
					  const wchar_t *word)
{
	if (dict)
	{
		if (*word == L'\0')
		{
			if (dict->key == NULL_MARKER)
			{
				delete_child(prev, dict);
				if (prev->children_size == 0)
					return 1;
				return 0;
			}
		}
		else
		{
			struct dictionary *found = NULL;
			word++;
			if (*word == L'\0')
				find_child(dict, &found, NULL_MARKER);
			else
				find_child(dict, &found, *word);
			if (delete_helper(found, dict, word))
			{
				delete_child(prev, dict);
				return (prev && prev->children_size == 0);
			}
		}
	}
	return 0;
}
/* Helper function for the destructor, recursively moves 
 * through the trie and deletes a node if it has no children
 *
 * Parameters:
 * 	Node* s: pointer to the current node
 */
void Trie::delete_helper(Node* s)
{
    // goes through all of it's children
    for(int i = 0; i < 36; i++){
	// if a child isn't null, recursively go to that child
	if(s->delete_child(i) != NULL){
	    Node* tmp = s->delete_child(i);
	    delete_helper(tmp);
	}
    }
    // delete node if it has no children
    delete s;
}
Exemple #4
0
int dictionary_delete(struct dictionary *dict, const wchar_t *word)
{
	if (dict == NULL || word == NULL)
		return 0;
	if (dictionary_find(dict, word))
	{
		struct dictionary *found = NULL;
		find_child(dict, &found, *word);
		delete_helper(found, NULL, word);
		return 1;
	}
	return 0;
}
// destructor
Trie::~Trie()
{
    Node* tmp = root;
    delete_helper(tmp);
}