Skip to content

Conversation

@sophie-kaleba
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@andreeapetcu andreeapetcu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments are clear and useful in understanding the code 👍 With some minor exceptions where I suggested improvements, your code is nicely structured


public String[] dictionary;
public Graph unorderedAlphabet;
public enum VertexState {WHITE, GREY, BLACK};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of using states instead of keeping an agenda of the visited vertices :) It would be great if you could add comments on what each state means (I assume WHITE is used for an unvisited vertex, GREY for the vertex that is currently being visited and BLACK for a visited vertex)

* it will iterate over both of the words and will add the characters to the alphabet.
* @return the alphabet built from the dictionary
*/
public List<Character> build() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT : I believe that buildAlphabet or findAlphabet would be more suggestive method names

*/
public void compareWords(String word1, String word2) {
if (word1.isEmpty() && word2.isEmpty()) {
throw new IllegalArgumentException("one of the words is empty");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor bug: if you want your method to throw an exception only if one of the words is empty you should use word1.isEmpty() || word2.isEmpty()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

else {longestWord = 2;}

if (longestWord == 1) this.browseLastLettersOfLongest(word1, sizeWord1, i);
else if (longestWord == 2) this.browseLastLettersOfLongest(word2, sizeWord2, i);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One possible style change :

if (sizeWord1 > sizeWord2) {
    this.browseLastLettersOfLongest(word1, sizeWord1, i);
} else {
    this.browseLastLettersOfLongest(word2, sizeWord2, i);
}

* @param c1 - the character coming from the first word
* @param c2 - the character coming from the second word
* @param firstDifference - true if it is the first time one encounters a difference in characters btwn the 2 words
*/
Copy link
Collaborator

@andreeapetcu andreeapetcu Jul 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add @return to make it easier to understand the return values of the method. I am a bit confused about this method's use in the if statement on line 128.

Map<Character, VertexState> marked = new LinkedHashMap<Character, VertexState>();

for (Character c : unsortedAlphabet.getContent().keySet()) {
marked.put(c, VertexState.WHITE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, you have your own style with the states 😄

*/
public void compareWords(String word1, String word2) {
if (word1.isEmpty() && word2.isEmpty()) {
throw new IllegalArgumentException("one of the words is empty");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

int longestWord;
int i = 0;

for (; i < Math.min(sizeWord1, sizeWord2); i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of Math class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants