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

📄 mylinkedlist.java

📁 用java编写的hashtable程序
💻 JAVA
字号:
/**
A class for flexible representating the linked list
Written by : H Yu
*/


public class MyLinkedList {

	//instance variables
    	private String word;
    	private int count;
    	private int index;
    	private MyLinkedList next;

	//constructor methods

	/**
	*creat an instance of the MyLinkedList class with the default values
	*/
	public MyLinkedList() {
		word=null;
		index=0;
		count=0;
		next=null;
	}

	/**
	*creat an instance of the MyLinkedList class with the specific values
	*@param w sets value of word
	*@param j sets value of index
	*/
    	public MyLinkedList(String w, int j) {
		word = w;
		index = j;
		count = 1;
		next = null;
    	}

	//mutator method

	/**
	*increase the count if w matches to the word 
	*creat a new object if w is not in the list
	*@param w word
	*/
    	public void setWord(String w) {
		if(word != null) {
			if (w.equals(word)) 
				count++;		
			else if (next != null) 
				next.setWord(w);
			else 
				next = new MyLinkedList(w,index+1);
		}
		else {
			word = w;
			count = 1;
		}
    	}

   	//accessor methods

	/**
	*return true if w exists in the list
	*@param w word
	*/ 
	public boolean isWord(String w) {
		boolean flag = false;
		if(word != null) {
			if (w.equals(word)) 
	    			flag = true;
			else if (next != null) 
	   	 		flag = next.isWord(w);
		}
		return(flag);
	}

	/**
	*return count if w matches to the word
	*@param w word
	*/
	public int getCount(String w) {
		if (w.equals(word)) {
			return(count);
		}
		else if (next != null) {
			return(next.getCount(w));
		}
		else {
			return(0);
		}
	}

	/**
	*return the length of the list
	*/
	public int getLength() {
		int length = 0;
		if(word != null) {
			if (next == null) {
				length = index+1;
			}
			else {
				length = next.getLength();
			}
		}
		else {
			length = 0;
		}			
		return(length);
	}

	/**
	*return the word if j matches the index
	*@param j index
	*/
	public String getWord(int j) {
		if (index == j) {
			return(word);
		}
		else if (next != null) {
			return(next.getWord(j));
		}
		else {
			return("null");
		}
	}

	/**
	*display the list
	*/
	public String toString() {
		
		return(index+" "+word+" "+count+" "+next);

	}

}

⌨️ 快捷键说明

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