1591990
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
typedef struct { char tendiem[5];
float hoanhdo,tungdo;
}diem;
typedef struct pt{
diem dl;
struct pt *ke;
}kpt;
float a,b;
void *trods;
diem ti;
kpt *q;
void*taodanhsach(void*trods);
void xemdanhsach(void*trods);
void bosungsau(void*trods,kpt *q,diem ti);
main()
{int n;
float a,b;
kpt *tam;
trods=taodanhsach(trods);printf("xem danh sach vua tao:
");
xemdanhsach(trods);
/*strcpy(hsi.hodem,"Nguyen Thi");
strcpy(hsi.ten,"Thom");
hsi.tuoi=15;*/
printf("moi nhap ten diem:");fflush(stdin);gets(ti.tendiem);
printf("moi nhap hoanh do");scanf("%f",&a);ti.hoanhdo=a;
printf("moi nhap tung do");scanf("%f",&b);ti.tungdo=b;
/*printf("bo sung sau phan tu dau tien");
tam=(kpt*)trods;
q=tam;*/
/*printf("bo sung sau phan tu thu 2:");
tam=(kpt*)trods;
q=tam->ke;*/
/*printf("bo sung sau phan tu cuoi cung:");
tam=(kpt*)trods;
while(tam->ke!=NULL) tam=tam->ke;
q=tam;*/
printf("bo sung sau phan tu thu n:
");scanf("%d",&n);
tam=(kpt*)trods;
for(int i=1;i<n;i++) tam=tam->ke;q=tam;
bosungsau(trods,q,ti);
printf("
xem danh sach sau khi bo sung sau:
");
xemdanhsach(trods);
getch();
}
void *taodanhsach(void *trods)
{
trods=NULL;
do{
kpt *tam;
printf("
Nhap diem (0de thoat):");fflush(stdin);gets(ti.tendiem);
if(strcmp(ti.tendiem,"0"))
{printf("moi nhap hoanh do:");scanf("%f",&a);ti.hoanhdo=a;
printf("nhap tung do: ");
scanf("%f",&b);
ti.tungdo=b;
tam=(kpt *)malloc(sizeof(kpt));
tam->dl=ti;
tam->ke=(kpt*)trods;
trods=tam;
}
}while (strcmp(ti.tendiem,"0"));
return trods;
}
void xemdanhsach(void *trods)
{
kpt *tam;
tam=(kpt*)trods;
while(tam!=NULL)
{
//hsi=tam->dl;
//printf("%s%s%d
",hsi.hodem,hsi.ten,hsi.tuoi);
printf("%s(%2.1f,%2.1f)
",tam->dl.tendiem,tam->dl.hoanhdo,tam->dl.tungdo);
tam=tam->ke;
}
getch();}
void bosungsau(void *trods, kpt *q, diem ti)
{
kpt *tam;
tam=(kpt *)malloc(sizeof(kpt));
tam->dl=ti;
tam->ke=q->ke;
q->ke=tam;
}
Bạn đang đọc truyện trên: Truyen247.Pro