dslk 2
struct DiaNhac
{
int Madia;
char Tendia[20];
char TenCS[20];
int SoBH;
int NamPH;
int Soluong;
};
struct Node
{
struct DiaNhac dianhac;
struct Node*Next;
};
typedef Node*Nodeptr;
Nodeptr MakeNode (DiaNhac x)
{
Nodeptr p = new Node;
p->dianhac = x;
p->next = null;
return p;
}
Nodeptr insert_first(Nodeptr &list,DiaNhac x)
{
Nodeptr p = MakeNode(x);
p->next=list;
list = p;
return p;
}
Nodeptr insert_after(Nodeptr q,DiaNhac x)
{
Nodeptr p = MakeNode(x);
p->next=q->next;
q->next=p;
return p;
}
void NhapDS (Nodeptr &list)
{
int n;
dianhac dn;
Nodeptr p;
cout<<"Nhap so luong Dia muon nhap:"<<n;
for(int i=0;i<n;i++)
{
cout<<"Nhap Dia thu:"<<i;
cout<<"Nhap Ma Dia: "; cin>>dn.Madia;
cout<<"Nhap Ten Dia:"; cin>>dn.Tendia;
cout<<"Nhap Ten CS:"; cin>>dn.TenCS;
.
.
if(i==0)
insert_first(p,dn);
else
insert_after(p,dn);
}
}
void DuyetDS (Nodeptr list)
{
Nodeptr p = list;
dianhac dn;
while(p!=null)
{
cout<<"Ma Dia: " <<p->dn.Madia;
cout<<"Ten Dia:" <<p->dn.Tendia;
.
.
.
p=p->next;
}
}
void TimDia(Nodeptr list)
{
char tendia[20];
cout<<"Nhap ten dia:"; cin>>tendia;
Nodeptr p = list;
while(p!=null)
{
if(p->dianhac.Tendia == tendia)
{
cout<<"Ten :"<< p->dianhac.Tendia;
cout<<"Madada: "<< p->dianhac.Tendia;
.
.
.
break;
}
else
p = p->next;
}
cout<<"Ko tim thay!";
}
int delFirst(Nodeptr &list)
{
if(list==null)
return 0;
Nodeptr p = list;
list =p->next;
delete p;
return 1;
}
int delAfter(Nodeptr q)
{
if(q->next !=null)
{
Nodeptr p = q->next;
q->next =p->next;
delete p;
return 1;
}
else
return 0;
}
void XoaDS(Nodeptr &list)
{
Nodeptr p = list;
Nodeptr q = null;
while(p!=null)
{
if(p-> dianhac.TenCS =="Don Nguyen")
{
if(q==null)
{
delFirst(list);
p=list;
}
else
{
p=p->next;
delAfter(q);
}
}
else
q=p;
p=p->next;
}
}
int Tongsoluong(Nodeptr list)
{
list dem=0;
Nodeptr p=list;
while(!p=null)
{
if(p->dianhac.NamPH == "2011")
dem += p->dianhac.Soluong;
p=p->next;
}
return dem;
}
void InDS(Nodeptr list)
{
Nodeptr p =list;
list dem=0;
while(!p=null)
{
if(p->dianhac.SoBH >10)
{
cout<<"Ma dia:" <<p->dianhac.Madia;
cout<<"Ten dia:" <<p->dianhac.Tendia;
.
.
.
p=p->next;
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top