danh sach lien ket don
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
struct phantu
{
int x;
phantu*next;
};
typedef phantu*tro;
void nhap(tro&dau)
{
tro p;
char ch;
dau=NULL;
do
{
p=new(phantu);
cout<<"
nhap x:";cin>>p->x;
p->next=dau;
dau=p;
cout<<"
nhan <esc> de ket thuc!";
ch=getch();
}
while (ch!=27);
}
void lietke(tro dau)
{
tro p;
cout<<"
phantu:
";
p=dau;
while(p!=NULL)
{
cout<<" "<<p->x;
p=p->next;
}
getch();
}
int max(tro dau)
{
int ln;
if( dau==NULL)
{
cout<<"danh sach rong" ;
return 0;
}
else
{
tro find=dau;
ln=find->x;
while(find!=NULL)
{
if(ln< find->x)
ln=find->x;
find=find->next;
}
return ln;
}
}
float Dem(tro dau)
{
tro p=dau;
float d=0;
while(p!=NULL)
{
d++;
p=p->next;
}
return d;
}
float Tong(tro dau)
{
tro p=dau;
float s=0;
while(p!=NULL)
{
s=s+p->x;
p=p->next;
}
return s;
}
float TB(tro dau)
{
float tb=0;
tb=Tong(dau)/Dem(dau);
return tb;
}
void main()
{
clrscr();
tro Dau;
nhap(Dau);
lietke (Dau);
int m;
m=max(Dau) ;
cout<<"
max la: "<<m;
cout<<"
dem = "<<Dem(Dau);
cout<<"
tong = "<<Tong(Dau);
cout <<"
tb = "<<TB(Dau);
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top