#include <stdio.h>
#include <string.h>
struct Student
{
int id;
char name[16];
Student* next;
};
Student ss[4]=
{
{ 1, "xxs",0 },
{ 2, "xxx",0 },
{ 3, "xxy",0 },
{ 4, "xxz",0 }
};
int main()
{
//链表构造
ss[0].next = &ss[1];
ss[1].next = &ss[2];
ss[2].next = &ss[3];
ss[3].next = 0;
//链表遍历
Student* p = &ss[0];
while (p)
{
printf("ID:%d, name:%s\n", p->id, p->name);
p = p->next;//下一个对象
};
return 0;
}
遍历链表(转载)
最新推荐文章于 2024-04-13 16:10:05 发布