stringlinkedlist.java

来自「本压缩文件中含有线程的控制」· Java 代码 · 共 63 行

JAVA
63
字号
package c10;

public class StringLinkedList {
	
	private ListNode head;
	
	public StringLinkedList(){
		head = null;
	}
	
	public int length(){
		int count = 0;
		ListNode position = head;
		while(position!=null){
			count++;
			position = position.getLink();
		}
		return count;
	}
	
	public void addANodeToStart(String addData){
		head = new ListNode(addData,head);
	}
	
	public void deleteHeadNode(){
		if(head!=null){
			head = head.getLink();
		}else{
			System.out.println("empty list!");
			System.exit(0);
		}
	}
	
	public boolean onList(String target){
		return (Find(target)!=null);
	}
	
	public void showList(){
		ListNode position = head;
		while(position!=null){
			System.out.println(position.getData());
			position = position.getLink();
		}
	}
	
	private ListNode Find(String target){
		ListNode position = head;
		String data;
		while(position!=null){
			data = position.getData();
			if(data.equals(target)){
				return position;
			}
			position = position.getLink();
		}
		
		return null;
	}
	
	

}

⌨️ 快捷键说明

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