⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myvocabularylist.java

📁 用java编写的hashtable程序
💻 JAVA
字号:
/**
Generate the vocabulary list using MyHash.java class, MyLinkedList.java class and MyHashFunction.java class
Written by : H Yu
*/


import sheffield.*;


public class MyVocabularyList{
   public static void main(String[] args){
	EasyReader file=new EasyReader("news.txt");
	EasyWriter outputfile=new EasyWriter("vocabulary.txt");
	//Count the numbers of accurrences of each words

	//crete a hashtable of the class MyHash
	MyHash ht = new MyHash();
    	
	//split many words and put the word into hashtable   		
    	while(!file.eof()){
           	String s=file.readString();
           	s=s.trim()+' ';
           	int l=s.length();
          	while(l>0){
              		int i=s.indexOf(' ');
              		String w1 = s.substring(0,i);
              		s = s.substring(i+1,l);
                        if(w1.length() != 0) 
           			ht.setWord(w1);  
           		l=s.length();
           		}
     		}

	ht.PrintHashTable();

	//reorder the vocabulary list

	//put the vocabulary list to the arrays
	int size=ht.getNumber();		
	String[] word=new String[size];
	int[] number=new int[size];
	int m=0;
     	for(int i=0;i<ht.getSize();i++) {
		int l=ht.getListLength(i);
		if(l > 0){
			for(int j=0;j<l;j++) {
				String key = ht.getWord(i,j);
	    			int value = ht.getCount(key);	
 				word[m]=key;
				number[m]=value;
     				m++;
 			}
		}
	}

	//sort the vocabulary list in the order of frequency and alphabetically
                int tem;
                String temp=new String(); 
		for(int i=0;i<size-1;i++){
			for(int j=i+1;j<size;j++){
				if(number[i]==number[j]){
                                	int comp=word[i].compareTo(word[j]);
					if(comp>0){            			
						tem=number[i];
						number[i]=number[j];
						number[j]=tem;
						temp=word[i];
						word[i]=word[j];
						word[j]=temp;
					}
                                }
				else if(number[i]<number[j]){
					tem=number[i];
					number[i]=number[j];
					number[j]=tem;
					temp=word[i];
					word[i]=word[j];
					word[j]=temp;
				}
			}
	        }

	//display the vocabulary list to vocabulary.txt      
	for(int i=0;i<size;i++){
		outputfile.print(word[i]);
                outputfile.println(number[i],20-word[i].length());
	}
	outputfile.println();
	outputfile.println("The total number of the words is: "+size);	
  }
}
		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -