-
Notifications
You must be signed in to change notification settings - Fork 0
/
danh sach lien ket.cpp
executable file
·79 lines (75 loc) · 1.27 KB
/
danh sach lien ket.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct sinhvien
{
char ten[30];
int masv;
float diemtk;
};
struct NODE
{
sinhvien infor;
struct NODE*Next;
};
struct LIST
{
NODE *Head;
NODE *Tail;
}l;
void khoitao(LIST &l)
{
l.Head=NULL;
l.Tail=NULL;
}
NODE * tao_nut(sinhvien x)
{
NODE *p;
p=new NODE;
if(p==NULL)
{printf("\n khong du bo nho:");
exit(0);
}
p->infor=x;
p->Next=NULL;
return p;
}
void tao_ds(LIST &l)
{
sinhvien x;
NODE *p;
do{
printf( "\n nhap ten sinh vien: ");fflush(stdin);
gets(x.ten);
if(x.ten==NULL) break;
printf("\n nhap ma sinh vien: ");
scanf("%d",&x.masv);
printf("\n Nhap diem tong ket: ");
scanf("%f",&x.diemtk);
p=tao_nut(x);
if(l.Head==NULL)
l.Head=l.Tail=p;
else
{
l.Tail->Next=p;
l.Tail=p;
}
}while(x.masv!=1);
}
void xuat(LIST l)
{ for(NODE *p=l.Head;p;p=p->Next)
{
printf("\nTen sinh vien la: %s",p->infor.ten);
printf("\nMa sinh vien: %d",p->infor.masv);
printf("\nDiem tong ket: %.1fd",p->infor.diemtk);
}
}
main()
{
sinhvien x;
LIST l;
khoitao(l);
tao_ds(l);
xuat(l);
getch();
}