javascript和JQuery焦点图和代码特效大全
当前最流行的开源CMS网站系统大全
当前位置:主页 > 编程开发 > JAVA技术 >

JAVA实现创建链表的方法

来源:网络编辑:网络发布于:2013-05-13人围观Java方法创建链表

JAVA实现创建链表的方法,具体代码如下:

public class Demo03{
class People{
private String name;
private int age;
private People nextpeople;
public void setNextPeople(People nextpeople){
this.nextpeople=nextpeople;
}
public People getNextPeople(){
return nextpeople;
}
public People(String name,int age){
this.name=name;
this.age=age;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public void println(){
System.out.println("Name:"+name+",Age:"+age);
}
}
private People rootpeople,currentpeople,people;
public void setPeople(String name,int age){
currentpeople=new People(name,age);
   if(rootpeople==null){
rootpeople=currentpeople;
people=rootpeople;
}else{
if(people.nextpeople==null){
people.nextpeople=currentpeople;
}
people=people.nextpeople;
}
}
public void show(){
people=rootpeople;
do{
people.println();
people=people.nextpeople;
}while(people!=null);
}
public static void main(String[] args){
Demo03 d1=new Demo03();
d1.setPeople("aaa",20);
d1.setPeople("bbb",21);
d1.setPeople("ccc",22);
d1.setPeople("ddd",23);
d1.setPeople("eee",24);
d1.setPeople("fff",25);
d1.setPeople("ggg",26);
d1.show();
}
}

Java,方法,创建,相关的文章
有时间的话来看看IT界的突发事件