[r]
(1)#include <stdio.h> #include <conio.h> #include <iostream.h> #include <iomanip.h> #include <string.h>
typedef struct {
char MSSV[5], hoten[30]; int diem;
} SV;
typedef SV elem; #include "BSTTQ.CPP"
int ssMS(SV x, SV y) {
return strcmp(x.MSSV, y.MSSV); }
void docfile(tree &t, char *fn) {
(2)SV x; t=NULL;
fread(&x, sz, 1, f); while (!feof(f)) {
inserttree(t, x, ssMS); fread(&x, sz, 1, f); }
fclose(f); }
void ghi(tree t, FILE *f) {
if (t!=NULL) {
ghi(t->left, f); ghi(t->right, f);
fwrite(&t->data, sizeof(SV), 1, f); }
}
void ghifile(tree t, char *fn) {
(3)fclose(f); }
void nhapds(tree &t) {
SV x; {
flushall();
cout<<"\nMa so SV:"; gets(x.MSSV);
if (searchtree(t, x, ssMS))
cout<<"Da co Ma so!\n"; else
if(x.MSSV[0]) {
cout<<"Ho tenSV:"; gets(x.hoten); cout<<"Diem :"; cin>>x.diem;
inserttree(t, x, ssMS); }
(4)void inds(tree t) {
if (t!=NULL) {
inds(t->left);
cout<<endl<<t->data.MSSV<<" "<<t->data.hoten<<setw(20-strlen(t->data.hoten))<<t->data.diem;
inds(t->right); }
}
void main() {
int chon; clrscr(); SV x; tree t, p;
docfile(t, "SL.DAT"); {
cout<<"\n============================================="; cout<<"\n1 Nhap ds";
cout<<"\n2 In ds";
cout<<"\n3 Tim kiem theo MSSV"; cout<<"\n4 Xoa theo MSSV"; cout<<"\nChon:";
(5)switch (chon) {
case 1:nhapds(t); break; case 2:inds(t); break; case 3:
do {
cout<<"\nTim:"; gets(x.MSSV);
if ((p=searchtree(t, x, ssMS))!=NULL) {
cout<<"\nTim thay";
cout<<endl<<p->data.MSSV<<" "<<p->data.hoten<<setw(20-strlen(p->data.hoten))<<p->data.diem;
}
else
cout<<"\nCo thay dau!!"; } while (x.MSSV[0]);
break; case 4:
do {
cout<<"\nXoa:"; gets(x.MSSV); if (x.MSSV[0])
deletetree(t, x, ssMS); } while (x.MSSV[0]);
(6)