首先你创建的这个,肯定不是动态链表,说是静态链表又不像,难以称呼
#include
#include
#include
struct student{
char name[20];
int age;
struct student* next;
};
int main()
{
int i, n;
int x, y = 0;
struct student stu[101];
// struct student *head;
stu[0].next = NULL; // 避免链表无数据
scanf("%d", &n);
for(i = 1; i <= n; i++)
scanf("%s %d", stu[i].name, &stu[i].age);
scanf("%d", &x);
for(i = 1; i <= n; i++){
if( stu[i].age != x ){
stu[y].next = &stu[i];
y = i;
stu[i].next = NULL;
}
}
struct student *p = &stu[0];
// stu[0]为头指针,不存储数据,因此先p->next
while( p->next != NULL ){
p = p->next;
printf("%s ", p->name);
}
return 0;
}