class Node
{
//当前节点
private String data;
//下个节点
private Node next; //当前节点
public void setData(String data){
this.data=data;
}
public String getData(){
return this.data;
} //下个节点
public void setNext(Node next){
this.next=next;
}
public Node getNext(){
return this.next;
}
} public class MyLink
{
public static void main(String args[]){ //第一个节点
Node node1 = new Node();
node1.setData("A"); //第二个节点
Node node2 = new Node();
node2.setData("B"); //第三个节点
Node node3 = new Node();
node3.setData("C"); //第四个节点
Node node4 = new Node();
node4.setData("D"); //设置第一个节点的下个节点
node1.setNext(node2); //设置第二个节点的下个节点
node2.setNext(node3); //设置第三个节点的下个节点
node3.setNext(node4); //输出所有节点
printNode(node1); } public static void printNode(Node node){ //输出当前节点信息
System.out.print(node.getData()+"-->"); //假如当前节点还有子节点
if(node.getNext()!=null){
printNode(node.getNext());//调用方法本身,传入子节点
}else{
System.out.print("null");
} } }

执行结果为:

A-->B-->C-->D-->null

最新文章

  1. [MFC] 高仿Flappy bird 桌面版
  2. paypal IPN 接口返回INVALID参数可能问题
  3. vim 常用命令总结
  4. javacript序列化表单数据
  5. Android多线程及异步处理问题
  6. sun.misc.BASE64Encoder我找不到jar一揽子解决方案
  7. Redis源代码分析(十一年)--- memtest内存测试
  8. XSD实例
  9. [SQL] 函数整理(T-SQL 版)
  10. Go学习笔记03-附录
  11. Oracle RAC环境下定位并杀掉最终阻塞的会话
  12. TensorFlow-Bitcoin-Robot:一个基于 TensorFlow LSTM 模型的 Bitcoin 价格预测机器人
  13. 让自己的开源项目支持CocoaPods
  14. Hystrix 配置参数全解析
  15. 初入webform的杂七杂八
  16. D6差分及树上差分
  17. jar包注册为Linux服务
  18. ios系统微信浏览器、safari浏览器中h5页面上拉下滑导致悬浮层脱离窗口的解决方法
  19. C51单片机中data、idata、xdata、pdata的区别
  20. wait&waitpid状态值

热门文章

  1. 【Unity】4.6 灯光
  2. Spring Cloud Consul
  3. CCDictionary
  4. ubantu 单用户模式进入系统
  5. 每日英语:A Chinese Soccer Club Has Won Something!
  6. ImportError: cannot import name 'main'的解决办法
  7. EL表达式取值中文再发送请求时会乱码
  8. Ubuntu 14.04环境变量修改
  9. STL之std::set、std::map的lower_bound和upper_bound函数使用说明
  10. js随机生成一个数组中的随机字符串以及更新验证码