Question: JAVA: Implement a sorted list ADT GIVEN_______________________________________ DictList.txt: public class DicList{ Node front; public void add(String word){ //TODO->add word to the sorted list front =

JAVA: Implement a sorted list ADT

JAVA: Implement a sorted list ADT GIVEN_______________________________________ DictList.txt: public class DicList{ Node

GIVEN_______________________________________

DictList.txt:

public class DicList{ Node front; public void add(String word){ //TODO->add word to the sorted list front = null; } public int size(){ int count=0; Node tmp=front; while(tmp!=null){ tmp=tmp.getNext(); count++; } return count; } public boolean isEmpty(){ return front ==null; } public void remove(int index){ //TODO->remove the node at the index if(index=0){ if(size()==1) front=null; else{ int loc=0; Node tmp=front; while(loc loc++; tmp=tmp.getNext(); } tmp.setNext(tmp.getNext().getNext()); } } } public void remove(Node node){ //TODO->remove the node from the list(the first occurrence of the word in the list int index=indexOf(node); if(index>=0) remove(index); }

public int indexOf(String word){ //TODO-> return the index of the first occurrence of the word in the list int index=-1; Node tmp=front; int loc=-1; while(tmp!=null && index == -1){ loc++; if(tmp.getVal() == word){ index=loc; }else{ tmp=tmp.getNext(); } } return index; } public int indexOf(Node node){ //TODO-> return the index of the first occurrence of the word in the list return indexOf(node.getVal()); } public boolean contains(String word){ //TODO-> check if the list contains the word return indexOf(word) != -1; }

public Node elementAt(int index){ //TODO->return the node at index if(index=size()) return null; int loc=0; Node tmp=front; while(loc loc++; tmp = tmp.getNext(); } return tmp; }

public String toString(){ //TODO-> list all words as: [Java, Programming, Cool] String s = "["; if(!isEmpty()){ s += front.getVal();

Node tmp = front.getNext(); while(tmp != null){ s += ", " + tmp.getVal(); tmp = tmp.getNext(); } } return s + "]"; }

public DicList sublist(int from, int end){ //TODO->create a sublist including elements at[from, end], if from including [fromNode, endNode], where fromNode is the first node >= min(word1,word2), and endNode is the last Node

Node.txt:

public class Node{

private String word; private Node next;

public Node(String word){ setWord(word); next=null; }

public String getWord(){ return word; } public Node getNext(){ return next; } public void setWord(String word){ this.word = word; } public void setNext(Node next){ this.next = next; } }

query.txt:

265 256 259 wonder wammus upperclassman 9999 java wammus wammus well wellcont xyridales

Design a driver program named App.java to test your implementation. At this point, you should be able to design your own driver program to test your codes. (Hint: you may use alphabet.txt to test your codes). If all your methods work as you expected, you are ready to move to the next task You need to complete the rest tasks in your workstation. Download words.dic, query.txt, DicList.java, Node.java, and App.java to your local computer. The file words.dic ha:s 20000 lines and each line contains a single word. The file query.txt contains queries you need to answer in your App.java Each line in query.txt represents a query. Your App.java should read and answer these queries. If a line in query.txt contains a single number N, then it represents the index of a node in the list, and your application should find and return the word in the (N+1)th node in the list; If it has two numbers N, and M, your application should list all words from index N to M, inclusive, in the format of [wordl, word2]; If it contains a single word, your application should find the index of word in the list( the first occurrence) If the line contains two words: W1 and W2, your application should list all words that are greater than Min(W1, W2) but less than Max(W1, W2), and all words that start with either W1 or W2. Write all responses to these queries to a file named response.txt. Use separate line for each response to each query. Design a driver program named App.java to test your implementation. At this point, you should be able to design your own driver program to test your codes. (Hint: you may use alphabet.txt to test your codes). If all your methods work as you expected, you are ready to move to the next task You need to complete the rest tasks in your workstation. Download words.dic, query.txt, DicList.java, Node.java, and App.java to your local computer. The file words.dic ha:s 20000 lines and each line contains a single word. The file query.txt contains queries you need to answer in your App.java Each line in query.txt represents a query. Your App.java should read and answer these queries. If a line in query.txt contains a single number N, then it represents the index of a node in the list, and your application should find and return the word in the (N+1)th node in the list; If it has two numbers N, and M, your application should list all words from index N to M, inclusive, in the format of [wordl, word2]; If it contains a single word, your application should find the index of word in the list( the first occurrence) If the line contains two words: W1 and W2, your application should list all words that are greater than Min(W1, W2) but less than Max(W1, W2), and all words that start with either W1 or W2. Write all responses to these queries to a file named response.txt. Use separate line for each response to each query

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!