Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void addToArray(String word, UniqueWord[] wordList) {
- // TODO
- UniqueWord toAdd = new UniqueWord(word);
- if (uniqueWordCount == wordList.length - 1) {
- increaseArray(wordList);
- }
- if (uniqueWordCount == 0) {
- wordList[0] = toAdd;
- uniqueWordCount++;
- } else {
- for (int i = 0; i < uniqueWordCount; i++) {
- if (toAdd.getWord().compareTo(wordList[i].getWord()) == 0
- || wordList[i] == null) {
- wordList[i].addCount();
- return;
- } else if (toAdd.getWord().compareTo(wordList[i].getWord()) < 0) {
- UniqueWord temp = wordList[i];
- UniqueWord temp2;
- wordList[i] = toAdd;
- for (int j = i + 1; j < uniqueWordCount; j++) {
- temp2 = wordList[j];
- wordList[j] = temp;
- temp = temp2;
- }
- uniqueWordCount++;
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement