Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. public static void addToArray(String word, UniqueWord[] wordList) {
  2.         // TODO
  3.         UniqueWord toAdd = new UniqueWord(word);
  4.         if (uniqueWordCount == wordList.length - 1) {
  5.             increaseArray(wordList);
  6.         }
  7.         if (uniqueWordCount == 0) {
  8.             wordList[0] = toAdd;
  9.             uniqueWordCount++;
  10.         } else {
  11.             for (int i = 0; i < uniqueWordCount; i++) {
  12.                 if (toAdd.getWord().compareTo(wordList[i].getWord()) == 0
  13.                         || wordList[i] == null) {
  14.                     wordList[i].addCount();
  15.                     return;
  16.                 } else if (toAdd.getWord().compareTo(wordList[i].getWord()) < 0) {
  17.                     UniqueWord temp = wordList[i];
  18.                     UniqueWord temp2;
  19.                     wordList[i] = toAdd;
  20.  
  21.                     for (int j = i + 1; j < uniqueWordCount; j++) {
  22.                         temp2 = wordList[j];
  23.                         wordList[j] = temp;
  24.                         temp = temp2;
  25.                     }
  26.                     uniqueWordCount++;
  27.                     return;
  28.                 }
  29.  
  30.             }
  31.         }
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement