import java.util.Vector; public class neverishDictionary { private Node head; private Vector result; public neverishDictionary() { head = null; } //begin inner node class private class Node { private String word, pos, def, date, org; private Node next; public Node(String word1, String pos1, String def1, String date1, String org1) //1st constructor { word = word1; pos = pos1; def = def1; date = date1; org = org1; next = null; } public Node(String word1, String pos1, String def1, String date1, String org1, Node nextNode) //2nd constructor { word = word1; pos = pos1; def = def1; date = date1; org = org1; next = nextNode; } public String getWord() { return word; } public String getPos() { return pos; } public String getDef() { return def; } public String getDate() { return date; } public String getOrg() { return org; } public void setNext(Node nextNode) { next = nextNode; } public Node getNext() { return next; } }//ends the inner class public boolean isEmpty() { return head == null; } public void addList(String newWord, String newPos, String newDef, String newDate, String newOrg) { Node curr; Node prev; Node newNode = new Node (newWord, newPos, newDef, newDate, newOrg); if(isEmpty()) { newNode.setNext(head); head=newNode; } else { newNode.setNext(head); head=newNode; } /* else { prev = head; curr = head; while (curr != null) { if (newWord.compareTo(curr.getWord())<0) { prev.setNext(newNode); newNode.setNext(curr); break; } else { prev = curr; curr = curr.getNext(); if (curr == null) { prev.setNext(newNode); } } */ // } //} } public void remove(String temp) { Node prev = head; Node curr = head; int x = 0; while (curr != null) { if (curr.getWord().equals(temp) && curr == head) { String resultWord = curr.getWord(); String resultPos = curr.getPos(); String resultDef = curr.getDef(); String resultDate = curr.getDate(); String resultOrg = curr.getOrg(); head = head.getNext(); } else { if (x == 0) { temp = curr.getWord(); curr = curr.getNext(); } else if(curr.getWord().equals(temp)) { String resultWord = curr.getWord(); String resultPos = curr.getPos(); String resultDef = curr.getDef(); String resultDate = curr.getDate(); String resultOrg = curr.getOrg(); curr = prev.getNext(); prev.setNext(curr.getNext()); } else curr=curr.getNext(); x++; } } //if the node you want to remove is the head, do this } public void search (String find) { Node prev = null; Node curr = head; String temp = " "; int x = 0; while (curr != null) { if (curr.getWord().equals(find)) { System.out.println("\nThe word: " + curr.getWord()); System.out.println("Part of Speech: " + curr.getPos()); System.out.println("Definition: " + curr.getDef()); System.out.println("Date Entered: " + curr.getDate()); System.out.println("Source: " + curr.getOrg()); break; } else { if (x == 0) { temp = curr.getWord(); curr = curr.getNext(); } else if(curr.getWord().equals(temp)) break; else curr=curr.getNext(); x++; } } } public Vector radixSort(Vector vlist) { final int NUMCHARS = 128; // +----------------+------------------------------------------ // | Public Methods | // +----------------+ /** * Sort stuff (a vector of strings) alphabetically. */ // Set up the result vector. Vector result = (Vector) vlist.clone(); // Set up the buckets. Vector[] buckets = new Vector[NUMCHARS]; for (int i = 0; i < NUMCHARS; i++) { buckets[i] = new Vector(); } // Determine the number of strings. int numStrings = vlist.size(); // Find the length of the longest string int len = 0; for (int i = 0; i < numStrings; i++) { String str = (String) result.get(i); if (str.length() > len) len = str.length(); } // for // Step through the positions from right to left, shoving into // buckets and then reading out again for (int pos = len-1; pos >=0; pos--) { // Put each string into the appropriate bucket for (int i = 0; i < numStrings; i++) { String str = (String) result.get(i); int bucketnum; // If the string is too short, shove it at the beginning if (str.length() <= pos) bucketnum = 0; else bucketnum = str.charAt(pos); buckets[bucketnum].add(str); } // Read it back out again, clearing the buckets as we go. result.clear(); for (int i = 0; i < NUMCHARS; i++) { result.addAll(buckets[i]); buckets[i].clear(); } // for(i) } // for(pos) //putitback (result);//put the vector into the list // That's it, we're done. System.out.println(); System.out.println("I am at the end of radix sort and printing the 'result' vector"); System.out.println(); System.out.println("radixsort is working fine but not utilizing the entire file"); System.out.println(); System.out.println(result); System.out.println(); return result; } // sort //method to pull out the string in the vector, add the other date in it //and throw it back onto the list in correct sorted order. /*public void putitback(Vector result) { String temp = " "; Node prev = null; Node curr = head; for (int x = 0; x < result.size(); x++) { temp = result.remove(x).toString(); if (curr.getWord().equals(temp)); { String word = curr.getWord(); String pos = curr.getPos(); String def = curr.getDef(); String date = curr.getDate(); String org = curr.getOrg(); remove(temp); addList(word, pos, def, date, org); } curr = curr.getNext(); } System.out.println(); System.out.println("I am at the end of putitback and printing the 'result' vector"); System.out.println(result); System.out.println(); }*/ public void displayAll() { Node prev1 = head; Node curr1 = head; while (curr1 != null) { System.out.println(curr1.getWord() + " (" + curr1.getPos() + ") " + curr1.getDef() + " " + curr1.getDate() + " " + curr1.getOrg() + "."); prev1 = curr1; curr1 = curr1.getNext(); } System.out.println(result); } }