<span style="font-size:18px;">class Students
{
String name;
int age;
Students(String name,int age)
{
this.name=name;
this.age=age;
}
void showinfo()
{
System.out.println("姓名"+this.name+"年龄"+this.age);
}
}
class node
{
Students data;
node next;
node()
{
}
node(Students data)
{
this.data = data;
this.next = null;
}
}
public class Linkdemo {
public static void init(Students[] ptr , node root)
{
node temp = root;
for(int i=0;i!=ptr.length;i++)
{
node neww = new node(ptr[i]);
temp.next = neww;
temp = temp.next;
}
}
public static void iterator(node root)
{
node temp = root;
while(temp.next!=null)
{
temp = temp.next;
temp.data.showinfo();
}
}
public static void main(String[] args)
{
Students[] stu= {
new Students("张三",20),
new Students("李四",19),
new Students("王五",21),
new Students("孙六",22),
new Students("何7",18)
};
node root = new node();
init(stu,root);
iterator(root);
}
}
</span>