linkedlist.java

来自「用Java实现链表存储输入数据」· Java 代码 · 共 70 行

JAVA
70
字号
package work_1;

//链表实现
public class LinkedList {
	private LinkNode headNode = null;
	private LinkNode tailNode = null;
	private LinkNode currentNode = null;
	private int length = 0;

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public LinkNode getHeadNode() {
		return headNode;
	}

	public void setHeadNode(LinkNode headNode) {
		this.headNode = headNode;
	}

	public LinkNode getTailNode() {
		return tailNode;
	}

	public void setTailNode(LinkNode tailNode) {
		this.tailNode = tailNode;
	}

	public LinkNode getCurrentNode() {
		return currentNode;
	}

	public void setCurrentNode(LinkNode currentNode) {
		this.currentNode = currentNode;
	}
	//增加节点
	public void addNode(LinkNode nodeInsert) {
		if (this.getLength() == 0) {
			headNode = nodeInsert;
			currentNode = headNode;
			this.length++;
		} else {
			currentNode.setNextLinkNode(nodeInsert);
			currentNode = nodeInsert;
			this.length++;
		}
	}

	// 判断是否到终点
	public boolean hasNextNode() {
		currentNode = currentNode.getNextNode();
		if (currentNode == null) {
			return false;
		} else {
			return true;
		}
	}
	//把链表头设为当前节点
	public LinkNode resetHead() {
		currentNode = headNode;
		return currentNode;
	}

}

⌨️ 快捷键说明

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