Ejemplo n.º 1
0
		// search for a key
		// Pre-condition: given the key to find
		//                given a subscript by reference
		//                given the type of search desired as a char, either
		//                        - 's' for simple lookups            or
		//                        - 'i' for insertion
		// Post-condition: true is returned if key is found
		//                 false is returned if key is not found
		//                 for type 's': 
		//                     subscript is set to position of the key or the first NULL encountered
		//                 for type 'i':
		//                     subscript is set to position of the key or the first tombstone encountered
		// Note: the search function has been modified to take three arguments instead of two
		//       as instructed in the assignment description
    bool search(std::string key, int& subscript, char type)
		{
			if (probeType == 'd')
				return searchD(key, subscript, type); //helper for double hash
			else 
				return searchQ(key, subscript, type); //helper for quad hash
		}
Ejemplo 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;
}