Vote count:
0
I have a list of words that all differ by one letter. I'm trying to make a word chain so that if the user enters one word, then the next word will differ by one character at random from that and then the next word will differ by one character of the last character.
Ex: test to nest to newt to nett to yett to yeti.
So I created the amount of words that differ by one letter to test. I created a swap method:
public static void swap( String[] str, int pos1, int pos2){
int temp = arr[pos1];
arr[pos1] = arr[pos2];
arr[pos2] = temp;
}
My professor recommended to swap the word to the last position in the list so that way you don't use it again, and then you look for a similar character position in the list that differs by one letter and then when you find that word, you keep swapping it to the end until you have no words left, or no similar positions left.
So my question is am I on the right track with swapping my words?
Swapping words in method for Word Chain
Aucun commentaire:
Enregistrer un commentaire