#include <iostream>
using namespace std;
struct Student
{
char name[20];
char sex;
int no;
int age;
Student *next;
};
Student *head;
Student *creat()
{
Student *ps;
Student *pend;
ps = new Student;
cin >> ps->name >> ps->sex >> ps->no >> ps->age;
head = NULL;
pend = ps;
while (ps->name != 0 && ps->sex != 0 && ps->no != 0 && ps->age != 0)
{
if (head == NULL)
head = ps;
else
pend->next = ps;
pend = ps;
ps = new Student;
cin >> ps->name >> ps->sex >> ps->no >> ps->age;
}
pend->next = NULL;
delete ps;
return (head);
}
void Delete(Student *head, int age)
{
Student *p;
if (!head)
{
cout << "\nlist null\n";return;
}
if (head->age == age)
{
p = head;
head = head->next;
delete p;
cout << age << " the head of list have been deleted\n";
}
for (Student *pGuard = head;pGuard->next;pGuard = pGuard->next)
{
if (pGuard->next->age == age)
{
p = pGuard->next;
pGuard->next = p->next;
delete p;
cout << age << " have been deleted\n";
return;
}
}
cout << age << " is not be found!\n";
}
void Showlist(Student *head)
{
cout << "now the items of list are\n";
while (head)
{
cout << head->name << "," << head->sex << "," << head->no << "," << head->age << endl;
head = head->next; //It is important to input the list.
}
}
int main()
{
cout << "请输入学生信息,信息全为0为输入完成。" << endl;
head = creat();
cout << "请输入要删除学生年龄:";
int age; cin >> age;
Delete(head, age);
Showlist(head);
system("pause");
}

using namespace std;
struct Student
{
char name[20];
char sex;
int no;
int age;
Student *next;
};
Student *head;
Student *creat()
{
Student *ps;
Student *pend;
ps = new Student;
cin >> ps->name >> ps->sex >> ps->no >> ps->age;
head = NULL;
pend = ps;
while (ps->name != 0 && ps->sex != 0 && ps->no != 0 && ps->age != 0)
{
if (head == NULL)
head = ps;
else
pend->next = ps;
pend = ps;
ps = new Student;
cin >> ps->name >> ps->sex >> ps->no >> ps->age;
}
pend->next = NULL;
delete ps;
return (head);
}
void Delete(Student *head, int age)
{
Student *p;
if (!head)
{
cout << "\nlist null\n";return;
}
if (head->age == age)
{
p = head;
head = head->next;
delete p;
cout << age << " the head of list have been deleted\n";
}
for (Student *pGuard = head;pGuard->next;pGuard = pGuard->next)
{
if (pGuard->next->age == age)
{
p = pGuard->next;
pGuard->next = p->next;
delete p;
cout << age << " have been deleted\n";
return;
}
}
cout << age << " is not be found!\n";
}
void Showlist(Student *head)
{
cout << "now the items of list are\n";
while (head)
{
cout << head->name << "," << head->sex << "," << head->no << "," << head->age << endl;
head = head->next; //It is important to input the list.
}
}
int main()
{
cout << "请输入学生信息,信息全为0为输入完成。" << endl;
head = creat();
cout << "请输入要删除学生年龄:";
int age; cin >> age;
Delete(head, age);
Showlist(head);
system("pause");
}
