package main
import"fmt"type Student struct{
Name string
Age int
Score float32
next *Student
}functrans(p *Student){for p !=nil{//p不为空
fmt.Println(*p)
p = p.next
}}funcmain(){var head Student //头节点学生
head.Name ="hua"
head.Age =18
head.Score =100var stu1 Student //学生1
stu1.Name ="stu1"
stu1.Age =23
stu1.Score =80//stu1.next = nil
head.next =&stu1
trans(&head)}
package main
import"math/rand"type Student struct{
Name string
Age int
Score float32
next *Student
}functrans(p *Student){for p !=nil{//p不为空
fmt.Println(*p)
p = p.next
}}funcmain(){var head Student //头节点学生
head.Name ="hua"
head.Age =18
head.Score =100var tail =&head
for i :=0; i <10; i++{var stu = Student{
Name: fmt.Sprintf("stu%d", i),
Age: rand.Intn(100),
Score: rand.float32()*100,}
tail.next =&stu
tail =&stu
}trans(&head)}