62,614
社区成员
发帖
与我相关
我的任务
分享
class Person{
public String name;
public void setname(String b){
name=b;
}
String getname(){
return name;
}
}
class Node {
public Person person;
public Node head;
public Node next;
public boolean isEmpty(){
return head==null;
}//判断链表是否为空
public void printAll(){
Node tmp=head;
if(isEmpty())
System.out.println("这是一个空链表");
while(tmp!=null){
System.out.print(tmp.person.getname()+" ");
tmp=tmp.next;
}
}//遍历链表打印结果
}
public class LianBiao {
public static void main(String [] args){
Node nod=new Node();
nod.person.setname("qq");
nod.next=new Node();
nod.head=nod;
Node tem=new Node();
tem=nod.next;
tem.person.setname("qw");
nod.printAll();
}
}
public Node() {
person = new Person();
}