用结构体构建单链表例子:
int main ()
{
struct student head;
struct student body;
struct student end;
struct student *p;
head.a = 10;
head.b = 20;
body.a = 30;
body.b = 40;
end.a = 50;
end.b = 60;
head.next = &body;
body.next = &end;
end.next = NULL;
p = &head;
do{
cout<<p->a<<p->b<<"\n";
p = p->next;
}while(p != NULL);
}
时间: 2024-10-07 18:47:16