zoukankan      html  css  js  c++  java
  • java 单向链表实现

    1 class Node{//Node类 
    2 private String data; 
    3 private Node next; 
    4 public Node(String data){ 
    5 this.data=data; 
    6 } 
    7 public String getData(){ 
    8 return this.data; 
    9 }
    10 public void setNext(Node next){
    11 this.next=next;
    12 }
    13 public Node getNext(){
    14 return this.next;
    15 }
    16 }
    17  
    18 public class LinkDemo1 {//主函数
    19 public static void main(String args[]){
    20 Node root=new Node("火车头");
    21 Node n1=new Node("车厢A");
    22 Node n2=new Node("车厢B");
    23 Node n3=new Node("车厢C");
    24 root.setNext(n1);
    25 n1.setNext(n2);
    26 n2.setNext(n3);
    27 printNode(root);
    28  
    29 }
    30 public static void printNode(Node node){//递归输出链表
    31 System.out.print(node.getData()+"	");
    32 if(node.getNext()!=null)
    33 printNode(node.getNext());
    34  
    35 }
    36 
    37 }
    判断一个结点以后是否还有后续结点,如果有,则输出,无,则采用递归的方法输出。。。
  • 相关阅读:
    查看占用内存cpu top10
    free 详解
    find
    服务器硬件查看
    firewalld命令使用
    firewalld-zone概念介绍
    Jenkins rpm包安装
    攻击防御案例
    filebeat收集系统登陆日志
    nginx转换json格式
  • 原文地址:https://www.cnblogs.com/zsqfightyourway/p/7115629.html
Copyright © 2011-2022 走看看