linkedlistclass.java

来自「最短路径和哈密顿通路」· Java 代码 · 共 84 行

JAVA
84
字号

public abstract class LinkedListClass {
	//definition of the node
	protected class LinkedListNode
	{
		DataElement info;
		LinkedListNode link;
	}
	//实例变量
	protected LinkedListNode first;
	protected LinkedListNode last;
	protected int count;
	//构造函数和方法
	public LinkedListClass() {
		first=null;
		last=null;
		count=0;
	}
	public LinkedListClass(LinkedListClass otherList) {
		first=otherList.first;
		last=otherList.last;
		count=otherList.count;
	}
	public void initializeList()
	{
		first=null;
		last=null;
		count=0;
	}
	public boolean isEmpty()
	{
		return(first==null);
	}
	public void print()
	{
		LinkedListNode current;
		current=first;
		while(current!=null)
		{
			System.out.print(current.info+"  ");
			current=current.link;
		}
	}
	public int length()
	{
		return count;
	}
	public DataElement front()
	{
		DataElement temp=first.info;
		return temp;
	}
	public DataElement back()
	{
		DataElement temp=last.info;
		return temp;
	}
	public abstract boolean search(DataElement searchItem);
	public void insertFirst(DataElement newItem){
		LinkedListNode newNode;
		newNode=new LinkedListNode();
		newNode.info=newItem;
	}
	public void insertLast(DataElement newItem)
	{
		LinkedListNode newNode;
		newNode=new LinkedListNode();
		newNode.info=newItem;
		newNode.link=null;
		if(first==null)
		{
			first=newNode;
			last=newNode;
		}
		else
		{
			last.link=newNode;
			last=newNode;
		}
		count++;
	}
	public abstract void deleteNode(DataElement deleteItem);
}

⌨️ 快捷键说明

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