📄 linkednode.java
字号:
package simple;
/** A basic linked node containing an item of type Object and a reference to the next node.
There are methods for accessing and setting the item and next node, and a toString method
that provides a string representation of the list of nodes starting with the current node. */
public class LinkedNode
{
/** The item of this node. */
protected Object item;
/** The next node. */
protected LinkedNode nextNode;
/** Construct a node with item x.
Analysis: Time = O(1) */
public LinkedNode(Object x)
{
item = x;
nextNode = null;
}
/** The item of the node.
Analysis: Time = O(1) */
public Object item()
{
return item;
}
/** Set the item to x.
Analysis: Time = O(1) */
public void setItem(Object x)
{
item = x;
}
/** The next node.
Analysis: Time = O(1) */
public LinkedNode nextNode()
{
return nextNode;
}
/** Set nextNode to x.
Analysis: Time = O(1) */
public void setNextNode(LinkedNode x)
{
nextNode = x;
}
/** String representation suitable for output.
Analysis: Time = O(n), n = number of nodes linked from this node */
public String toString()
{
String temp = item.toString();
if (nextNode != null)
temp += " " + nextNode.toString();
return temp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -