java链表打印_java链表打印

2022-08-20 10:29:59 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

链表类

package com.demo;

public class Node {

private String data;

private Node next;

public Node(String data) {

this.data=data;

}

public String getData() {

return data;

}

public void setData(String data) {

this.data = data;

}

public Node getNext() {

return next;

}

public void setNext(Node next) {

this.next = next;

}

}

打印链表的数据

package com.demo;

public class NodeTest {

public static void main(String[] args) {

Node no1=new Node(“林正英”);

Node no2=new Node(“林正英1”);

Node no3=new Node(“林正英2”);

no1.setNext(no2);

no2.setNext(no3);

print(no1);

}

private static void print(Node current) {

if(current==null) {

return ;

}

System.out.println(current.getData());

print(current.getNext());

}

//刪除一個鏈錶數據

public static void delete(Node deldata) {

}

}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/136602.html原文链接:https://javaforall.cn

0 人点赞