//链表
class Node{
private String data;//节点内容
private Node next; //保存下个节点
public Node(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 Duix10_2 {
public static void main(String[] args) {
Node n =new Node("火车头");
Node n1 =new Node("第一");
Node n2=new Node("第二");
Node n3 =new Node("结尾");
n.setNext(n1);
n1.setNext(n2);
n2.setNext(n3);
n3.setNext(null);
// System.out.println(n.getData());
// System.out.println(n.getNext().getData());
// System.out.println(n1.getNext().getData());
// String str="";
Node p=n;
while(p!=null){
System.out.println(p.getData());
p=p.getNext();
}
// for(int i=0;i<4;i++){
// str+=n.getData();
// n=n.getNext();
// }
// System.out.println(str);

}
}

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
猜你喜欢
  • 2021-10-26
  • 2022-12-23
  • 2021-10-14
  • 2021-09-02
  • 2021-04-15
  • 2021-10-09
  • 2021-04-03
  • 2022-02-16
相关资源
相似解决方案