Exemplo n.º 1
0
//查找
link searchR(link h, Key v){
	//Key t = key(h->item);
	Key t = h->item;
	link tmp = NULL;
	nr++;
	if (h == z)
		return NULL;
	if eq(v, t)
		return h;
	if less(v, t){
		if ((tmp = searchR(h->l, v)) != NULL){
			h->l = tmp;	h = rotR(h);
		}
		else
			return NULL;
	}
	else{
		if ((tmp = searchR(h->r, v)) != NULL){
Exemplo n.º 2
0
/*
  The following functions search the GameBoard for the word. A copy of the
  board is saved and then the function begins to search. First the function
  looks for anywhere the first letter of the word appears in the board. The
  folling if-statements only allow the word to search the board if it is within
  the scope of the related search algorithm (if the first letter of the word
  is in the upper left corner of the board, there is no need to search UL, U,
  UR, DL, or L because the word cannot possibly fit in these directions). Once
  the word is found the direction the word was found in is saved and the
  searching stops.
*/
void Word::searchBoard(GameBoard& board)
{
  //a copy of the board is saved
  array = new char*[board.getSize()];
  for(int i = 0; i < board.getSize(); i++)
  {
    array[i] = new char[board.getWidth()];
    strcpy(array[i], board[i]);
  }

  //searching starts
  for(int i = 0; i < board.getSize(); i++)
  {
    for(int j = 0; j < board.getWidth(); j++)
    {
      //if the first letter is found the searching gets more specific
      if(word[0] == array[i][j] && wordFound == 0)
      {
        //all of the following if-statements determine if the first letter is
        //in a place where the folling search function is applicable
        if(i - length >= -1 && j - length >= -1)
          searchUL(i, j);
        if(i - length >= -1)
          searchU(i, j);
        if(i - length >= -1 && board.getWidth() - length >= j)
          searchUR(i, j);
        if(board.getWidth() - length >= j)
          searchR(i, j);
        if(board.getSize() - length >= i && board.getWidth() - length >= j)
          searchDR(i, j);
        if(board.getSize() - length >= i)
          searchD(i, j);
        if(board.getSize() - length >= i && j - length >= -1)
          searchDL(i, j);
        if(j - length >= -1)
          searchL(i, j);
      }
    }
  }
  //deallocates the copy of board
  for(int i = 0; i < board.getSize(); i++)
    delete[] array[i];
  delete[] array;
}
Exemplo n.º 3
0
static Item searchR(link h, key v)
{
    Key t = key(h->item);
    if(h == z) return NULLitem;
    if(eq(v,t)) return h->item;
    if(less(v,t)) return searcR(h->l,v);
    else return searchR(h->r,v);
    /* Algoritmo recursivo para busca:
     *
     *      |---------------|
     *      |      ( )      | Vamos olhando o valor
     *      |      / \      | de cada um, a partir
     *      |     /   \     | da raiz, e dividindo
     *      |    /     \    | para uma das subárvores
     *      |-------|-------| conforme o valor.
     *      |  ( )  |  ( )   
     *      |  / \  |  / \   
     *      |---|---| /   \  
     *       [z]|[z]|[z] [z] 
     *          |---|          
     */
}
Exemplo n.º 4
0
Item STsearch(Key v) 
{
return searchR(head, v);
}
Exemplo n.º 5
0
	T search(key v){
		return searchR(head, v, 0);
	}
Exemplo n.º 6
0
/******************************************************************************************
* AVLprocura()
*
* Arguments:    head:   ponteiro para a cabeca da arvore AVL
*               v:      key a procurar na arvore
*
* Returns: Item - retorna um Item se este for encontrado, senao retorna NULLitem
*
* Description:  chama funcao de procura na arvore
*****************************************************************************************/
Item AVLprocura(link head, Key v){
    return searchR(head, v);
}
Exemplo n.º 7
0
Arquivo: link.c Projeto: ZoneMo/backup
Item searchR(link t, Key v)
  { 
    if (t == z) return NULLitem;
    if (eq(key(t->item), v)) return t->item;
    return searchR(t->next, v);
  }
Exemplo n.º 8
0
Item *STsearch(Key v, link head) {
    return searchR(head, v);
}
Exemplo n.º 9
0
/*Função envelope*/
Item_lema st_lema_search(Key_lema v)
{
    return searchR(heads[hash(v, M)], v);
}
Exemplo n.º 10
0
/*Procura chave na tabela*/
static Item_lema searchR(link t, Key_lema v)
{
    if (t == z) return NULLitem_lema;
    if (eq_lema(key_lema(t->item), v)) return t->item;
    return searchR(t->next, v);
}
Exemplo n.º 11
0
Item STsearch (Key searchKey) { 
  return searchR (rootNodeLink, searchKey); 
}