package test;
//目标:创建链表,实现链表结点的尾部插入
class Node_5{
private String data;
public Node_5 nextNode;
public void setData(String indata){
this.data=indata;
}
public String getData(){
return this.data;
}
public void setNextNode(Node_5 newNode){
this.nextNode=newNode;
}
public Node_5 getNextNode(){
return this.nextNode;
}
public void addData(String indata){
setData(indata);
Node_5 node_5=new Node_5();
Node_5 head=node_5;
if(node_5.getData()==null){
node_5.setData(indata);
System.out.println(node_5.getData());
}
else{
node_5.setNextNode(node_5);
node_5.setData(indata);
System.out.println(node_5.getData());
}
}
}
public class T_5 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Node_5 node_5=new Node_5();
for(int i=1;i<=3;i++){
node_5.addData("第"+i+"结点");
}
}
}
java中创建链表,实现链表的尾部插入
最新推荐文章于 2023-03-18 22:41:31 发布