#include<iostream>
using namespace std;
typedef struct node
{
char name[20];
char sex[20];
int no;
int age;
struct node *next;
}stud;
stud *create(int n)
{
stud *head, *p1, *p2;
head=p1=p2=NULL;
for(int i=0; i<n; ++i)
{
p1=(stud *)malloc(sizeof(stud));
cout<<"Enter name, sex, no, age:"<<endl;
cin>>p1->name>>p1->sex>>p1->no>>p1->age;
if(i==0)
head=p1;
else
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return head;
}
stud* del(stud *head ,int age1)
{
bool feel=false;
if(head)
{
stud *p=head,*q=NULL;
while(p->age!=age1 && p->next!=NULL )
{
q=p;
p=p->next;
}
if(p->age==age1)
{
if(p==head)
head=p->next;
else
q->next=p->next;
free(p);
feel=true;
}
}
cout<<feel<<endl;
return head;
}
int main()
{
stud *s;
s=create(3);
s=del(s,22);
while(s!=NULL)
{
cout<<s->name<<" "<<s->sex<<" "<<s->no<<" "<<s->age<<endl;
s=s->next;
}
return 0;
}
using namespace std;
typedef struct node
{
char name[20];
char sex[20];
int no;
int age;
struct node *next;
}stud;
stud *create(int n)
{
stud *head, *p1, *p2;
head=p1=p2=NULL;
for(int i=0; i<n; ++i)
{
p1=(stud *)malloc(sizeof(stud));
cout<<"Enter name, sex, no, age:"<<endl;
cin>>p1->name>>p1->sex>>p1->no>>p1->age;
if(i==0)
head=p1;
else
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return head;
}
stud* del(stud *head ,int age1)
{
bool feel=false;
if(head)
{
stud *p=head,*q=NULL;
while(p->age!=age1 && p->next!=NULL )
{
q=p;
p=p->next;
}
if(p->age==age1)
{
if(p==head)
head=p->next;
else
q->next=p->next;
free(p);
feel=true;
}
}
cout<<feel<<endl;
return head;
}
int main()
{
stud *s;
s=create(3);
s=del(s,22);
while(s!=NULL)
{
cout<<s->name<<" "<<s->sex<<" "<<s->no<<" "<<s->age<<endl;
s=s->next;
}
return 0;
}