java里链表的包_Java数据结构之单链表

public class Node {

int data;

Node next;

public Node(int data)

{

this.data = data;

}

//为节点追加节点

public Node append(Node node) //返回值改成Node的好处:n1.append(n2).append(n3).append(n4);//可无限追加

{

//当前节点

Node currentNode = this;

while(true)

{

Node nextNode = currentNode.next;

if(nextNode == null)

{

currentNode.next = node;

break;

}

else

{

currentNode = nextNode;

}

}

return this;

}

//获取下一个节点

public Node next()

{

return this.next;

}

//获取节点中的数据

public int getData()

{

return this.data;

}

//判断当前节点是否是最后一个节点

public boolean isLast()

{

return this.next == null;

}

//显示所有节点的值

public void show()

{

Node current = this;

while(true)

{

if(current == null)

{

break;

}

else

{

System.out.print(current.data+" ");

current = current.next;

}

}

System.out.println();

}

//删除单链表中的一个节点

public void deleteNext()

{

this.next = this.next.next;

}

//插入一个节点,插入的位置为当前节点的next

public void insertNext(Node node)

{

node.next = this.next;

this.next = node;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值