/*方法名称及作用 !!!!2
public 数据类型 toArray() 将链表以对象数组的形式返回
需要增加一个返回的数组属性内容。 private String [] retArray;
*/
class Link{
private class Node{
private String data;
private Node next;
public Node(String data){
this.data = data;
}
public void addNode(Node newNode){ //增加方法
if(this.next == null){
this.next = newNode;
}else{
this.next.addNode(newNode);
}
}
public boolean containsNode(String data){ //根据内容查询数据
if(data.equals(this.data)){
return true; //后面不再查询
}
else{
if(this.next != null){//有后续节点,继续查询
return this.next.containsNode(data);
}// 没有后续节点 , 返回false
else{
return false;
}
}
}
/* public void printNode(Node node){ //输出数据
System.out.print(this.data+"->");
if(node.next != null)
this.next.printNode(next);
}*/
public String getNode(int index){//查询指定索引内容
if(Link.this.foot++ == index){ //不相等自动
Java链表之输出(重点)
最新推荐文章于 2023-03-10 18:48:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)