Example #1
0
ListArrayIterator<String>* String::getTokens(char token)
{
    int num_tokens = numTokens(token);
    ListArray<String>* strings = new ListArray<String>();

    int start = 0;
    for (int j = 0; j < num_tokens; j++)
    {
        int index = indexOf(token, start);  //the index of the next token
        char* temp = new char[index - start + 1];

        for (int i = start; i < index; i++)
        {
            temp[i - start] = charAt(i);
        }
        temp[index - start] = 0;  //set null terminator
        start = index + 1;

        String* str = new String(temp);
        strings->add(str);

        delete[] temp;
    }

    ListArrayIterator<String>* token_iter = strings->iterator();
    delete strings;
    return token_iter;
}
Example #2
0
void Password::guess(int try_password, int num_matches)
{
   ListArray<String>* list = new ListArray<String>();
   for(int i = 1; i <= viable_words->size(); i++)
   {
      int matches = getNumMatches(all_words->get(try_password), viable_words->get(i)); 
      if(matches == num_matches)
      {
         list->add(viable_words->get(i));
      }

   }

   delete viable_words;
   viable_words = list;
   
}
void Password::guess(int try_password, int num_matches){
    String* original_word = getOriginalWord(try_password);
    
    ListArrayIterator<String>* iter_viable_words = viable_words->iterator();
    ListArray<String>* temp = new ListArray<String>();
    
    while(iter_viable_words->hasNext()){
      String* comp_word = iter_viable_words->next();
      
      int count = getNumMatches(original_word, comp_word);
      
      if(count == num_matches){
        temp->add(comp_word);
      }
    }
    delete viable_words;
    viable_words = temp;
}
Example #4
0
void Password::guess(int try_password, int num_matches)
{
	String* guessWord = all_words->get(try_password);
	ListArray<String>* newList = new ListArray<String>();
	ListArrayIterator<String>* iter = viable_words->iterator();

	while(iter->hasNext())
	{
		{
			String* c_word = iter->next();
			int match = getNumMatches(guessWord , c_word);
			if(match == num_matches)
			newList->add(c_word);
		}
		delete viable_words;
		viable_words = newList;
	}	
}