Open vnmh99 opened 6 years ago
`// DSLK QLSV 3.cpp : This file contains the 'main' function. Program execution begins and ends there. //
using namespace std;
typedef struct tagSINHVIEN { int Mssv; char Hoten[35]; int ngay, thang, nam; float Toan; float Van; float TK; }SINHVIEN, *PSINHVIEN;
typedef struct tagNODE { SINHVIEN Data; tagNODE Next; }NODE, PNODE;
typedef struct tagLIST { NODE Dau; NODE Cuoi; }LISTSV, *PLIST;
//Khoi tao NODE NODE KhoitaoNode() { NODE x = (NODE*)malloc(sizeof(NODE)); if (x == NULL) { printf_s("\n Bo nho khong du "); return 0; } x->Next = NULL; return x; }
//Khoi tao danh sach LISTSV void KhoitaoList(LISTSV* x) { x->Dau = NULL; x->Cuoi = NULL; }
//Nhap thong tin sinh vien void Nhap(NODE* x) { char tam[25]; int a, d, m, y; float t, c; printf_s("\nNhap ma Sinh vien: "); fflush(stdin); scanf_s("%d", &a); x->Data.Mssv = a;
printf_s("Nhap ten Sinh Vien: ");
fflush(stdin);
gets_s(tam);
strcpy_s(x->Data.Hoten, tam);
do
{
printf_s("Nhap Ngay Sinh: ");
fflush(stdin);
scanf_s("%d", &d);
} while (d > 31 || d < 1);
x->Data.ngay = d;
do
{
printf_s("Nhap Thang Sinh: ");
fflush(stdin);
scanf_s("%d", &m);
} while (m > 12 || m < 1);
x->Data.thang = m;
do
{
printf_s("Nhap Nam Sinh: ");
fflush(stdin);
scanf_s("%d", &y);
} while (y > 9999 || y < 1000);
x->Data.nam = y;
do
{
printf_s("Nhap Diem Toan: ");
fflush(stdin);
scanf_s("%f", &c);
} while (c < 0 || c > 10);
x->Data.Toan = c;
do
{
printf_s("Nhap Diem Van: ");
fflush(stdin);
scanf_s("%f", &t);
} while (c < 0 || c > 10);
x->Data.Van = t;
x->Data.TK = (x->Data.Toan + x->Data.Van) / 2;
x->Next = NULL;
}
void InSV(NODE* p) { printf_s("\nMa Sinh vien: %d ", p->Data.Mssv); printf_s("\tTen Sinh vien: %s ", p->Data.Hoten); printf_s("\nNgay/ Thang/ Nam sinh: %5d/%5d/%5d ", p->Data.ngay, p->Data.thang, p->Data.nam); printf_s("\nDiem Toan: %.2f ", p->Data.Toan); printf_s("\tDiem Van: %.2f ", p->Data.Van); printf_s("\tDiem tong ket: %.2f\n\n\n", p->Data.TK); }
void InDanhSach(LISTSV x) { NODE *p; p = x.Dau; while (p != NULL) { InSV(p); p = p->Next; } }
void ThemCuoi(LISTSV x, NODE t) { if (x->Dau == NULL) { x->Dau = t; } else { x->Cuoi->Next = t; } x->Cuoi = t; }
int NhapSV(LISTSV x) { NODE a = KhoitaoNode(); Nhap(a); ThemCuoi(x, a); return 0; }
void TimKiem(LISTSV x, int n) { NODE *p; p = x.Dau; int dem = 0; while (p != NULL) { if (p->Data.Mssv == n) { InSV(p); dem++; } p = p->Next; } if (dem == 0) { printf_s("\n Khong co sinh vien dat tieu chuan can tim\n"); } }
int XoaSV(LISTSV x, int n) { NODE p = x->Dau, *q; q = NULL; while (p != NULL) { if (p->Data.Mssv == n) break; q = p; p = p->Next; } if (p == NULL) return 0; //không tim thay if (q != NULL) { x->Cuoi = q; q->Next = p->Next; delete p; } else { x->Dau = p->Next; if (x->Dau == NULL) x->Cuoi = NULL; } return 1; }
void giaiphong(LISTSV x) { NODE p = x->Dau; NODE *a; while (p->Next != NULL) { a = p; p = p->Next; free(a); } }
void inSVGioi(LISTSV x) { NODE *p; p = x.Dau; int dem = 0; while (p != NULL) { if (p->Data.TK >= 8) { InSV(p); dem++; } p = p->Next; } if (dem == 0) { printf_s("\n Khong co sinh vien dat tieu chuan can tim\n"); } }
void inSVKha(LISTSV x) { NODE p; p = x.Dau; int dem = 0; while (p != NULL) { if (p->Data.TK < 8 && p->Data.TK >= 7) { InSV(p); dem++; } p = p->Next; } if (dem == 0) { printf_s("\n Khong co sinh vien dat tieu chuan can tim\n"); } } void inSVThilai(LISTSV x) { NODE p; p = x.Dau; int dem = 0; while (p != NULL) { if (p->Data.Toan < 5 || p->Data.Van < 5) { InSV(p); dem++; } p = p->Next; } if (dem == 0) { printf_s("\n Khong co sinh vien dat tieu chuan can tim\n"); } }
void SVHocLai(LISTSV x) { NODE *p; int n = 0; p = x.Dau; int dem = 0; while (p != NULL) { if (p->Data.Toan < 5 && p->Data.Van < 5) { n++; dem ++ ; } p = p->Next; } if (dem == 0) { printf_s("\n Khong co sinh vien dat tieu chuan can tim\n"); } }
// Liet ke Sinh vien Sinh vao thang 10 int Menu() { int a; int Ma; LISTSV x; KhoitaoList(&x); do { printf_s("\n\nMENU\n\n\n"); printf_s("\n\n\n 1.Nhap danh sach sinh vien "); printf_s("\n 2.Liet ke danh sach sinh vien "); printf_s("\n 3.Tim kiem sinh vien theo MSSV"); printf_s("\n 4.Liet ke danh sach sinh vien dat loai gioi"); printf_s("\n 5.Liet ke danh sach sinh vien dat loai Kha"); printf_s("\n 6.Liet ke danh sach sinh vien Phai thi lai"); printf_s("\n 7.Tong so sinh vien phai hoc lai"); printf_s("\n 8.Xoa sinh vien theo MSSV"); printf_s("\n 0.Thoat\n"); printf_s("\n\n\n"); scanf_s("%d", &a); printf_s("\nBan da chon : \n"); switch (a) { case 1: { printf_s("1.Nhap danh sach sinh vien\n"); int n; printf_s("\nNhap so luong sinh vien : "); scanf_s("%d", &n); for (int i = 1; i <= n; i++) { printf_s("\nNhap sinh vien thu: %d \n", i); NhapSV(&x); } break; } case 2: { printf_s("2.Liet ke danh sach sinh vien\n"); InDanhSach(x); break; } case 3: { printf_s("3.Tim kiem sinh vien theo MSSV\n"); fflush(stdin); printf_s("\nNhap Ma Sinh Vien can tim:"); scanf_s("%d", &Ma); TimKiem(x, Ma); break; } case 4: { printf_s("4.Liet ke danh sach sinh vien dat loai gioi\n"); inSVGioi(x); break; } case 5: { printf_s("5.Liet ke danh sach sinh vien dat loai Kha\n"); inSVKha(x); break; } case 6: { printf_s("6.Liet ke danh sach sinh vien Phai thi lai\n"); inSVThilai(x); break; } case 7: { printf_s("7.Tong so sinh vien phai hoc lai\n"); SVHocLai(x); break; } case 8: { printf_s("\n 8.Xoa sinh vien theo MSSV"); fflush(stdin); printf_s("\nNhap MSSV can xoa:"); scanf_s("%d", &Ma); fflush(stdin); XoaSV(&x, Ma); break; } case 0: { break; } default: printf_s("\nBan chon sai vui long chon lai!"); } } while (a != 0); giaiphong(&x); return 1; } int main() { Menu(); return 0; } `
` // DSLK QLSV 3.cpp : This file contains the 'main' function. Program execution begins and ends there. //
using namespace std;
//cau truc mon hoc struct MONHOC { char mmh[9]; char tenmh[50]; int sotc; float diem;
};
//cau truc 1 node trong danh sach mon hoc typedef struct MH_node MH_ptr; struct MH_node { MONHOC MH; MH_ptr *next; };
//cau truc danh sach mon hoc typedef struct MH_ds DSMH_ptr; struct MH_ds { int MH_numnode; MH_ptr MH_HEAD, MH_TAIL; };
// cau truc sinh vien struct SINHVIEN { int Mssv; char Hoten[35]; int ngay, thang, nam; DSMH_ptr MH_ds; int tongtc; float tbc; };
// cau truc mot node trong danh sach sinh vien typedef struct SV_node SV_ptr; struct SV_node { SINHVIEN SV; SV_ptr next; }; // cau truc danh sach sinh vien typedef struct SV_ds DSSV_ptr; struct SV_ds { int SV_numnode; SV_ptr SV_head, SV_tail; }; void taoDSMH(SV_node &p); void taoDSSV(DSSV_ptr *&list);
void nhapMH(SV_ptr *&MH_newnode);
void nhapSV(DSSV_ptr *&list);
void Output(DSSV_ptr list);//xuat danh sach; void Output2(SV_node p); void tinhdtb(SV_ptr *&p); int main() {
DSSV_ptr *list = new DSSV_ptr;
taoDSSV(list);
nhapSV(list);
cout << list->SV_head->SV.Hoten << endl;
cout << list->SV_tail->SV.Hoten << endl;
Output(list);
} void taoDSMH(SV_node &p) { p->SV.MH_ds.MH_numnode = 0; p->SV.MH_ds.MH_HEAD = NULL; p->SV.MH_ds.MH_TAIL = NULL; } void taoDSSV(DSSV_ptr &list) { list->SV_head = NULL; list->SV_tail = NULL; list->SV_numnode = 0;
} void nhapMH(SV_ptr *&MH_newnode) { taoDSMH(MH_newnode); char MH_select[1]; int temp = 1;
do
{
MH_ptr *p = new MH_ptr;
p->next = NULL;
p->MH.sotc = 0;
if (MH_newnode->SV.MH_ds.MH_numnode > 0)
{
MH_newnode->SV.MH_ds.MH_TAIL->next = p;
MH_newnode->SV.MH_ds.MH_TAIL = p;
}
else
{
p->next = MH_newnode->SV.MH_ds.MH_HEAD;
MH_newnode->SV.MH_ds.MH_HEAD = p;
MH_newnode->SV.MH_ds.MH_TAIL = p;
}
cin.ignore();
cout << " " << temp << ".Ma mon hoc: ";
cin.getline(p->MH.mmh, 9);
cout << " Ten mon hoc: ";
cin.getline(p->MH.tenmh, 50);
cout << " So tin chi : ";
cin >> p->MH.sotc;
cout << " Diem ";
cin >> p->MH.diem;
cout << endl << "Nhap them mon hoc ? [Y/N]" << endl;
cin >> MH_select[0];
temp++;
MH_newnode->SV.MH_ds.MH_numnode++;
cout << MH_newnode->SV.MH_ds.MH_numnode << endl << endl;
} while (MH_select[0] == 'Y' || MH_select[0] == 'y');
tinhdtb(MH_newnode);
}
void nhapSV(DSSV_ptr &list) { char tieptuc; do { SV_ptr SV_newnode = new SV_ptr; SV_newnode->next = NULL; if (list->SV_numnode > 0) { list->SV_tail->next = SV_newnode; list->SV_tail = SV_newnode; } else { SV_newnode->next = list->SV_head; list->SV_head = SV_newnode; list->SV_tail = SV_newnode; } cout << "Nhap MSSV : " << endl; cin >> SV_newnode->SV.Mssv; cin.ignore(); cout << "Nhap ho ten sinh vien : "; cin.getline(SV_newnode->SV.Hoten, 35); cout << "Nhap ngay/thang/nam sinh :"; cin >> SV_newnode->SV.ngay; cin >> SV_newnode->SV.thang; cin >> SV_newnode->SV.nam; cout << "Nhap mon hoc : " << endl; nhapMH(SV_newnode); /SV_newnode->SV.MH_ds.MH_HEAD->MH.tbc = SV_newnode->SV.MH_ds.MH_HEAD->MH.td / SV_newnode->SV.MH_ds.MH_HEAD->MH.tongtc;/ cout << endl << "Nhap them sinh vien ? [Y/N]" << endl; cin >> tieptuc; list->SV_numnode++; cout << list->SV_numnode << endl; } while (tieptuc == 'y' || tieptuc == 'Y');
}
void Output2(SV_ptr p)
{
MH_ptr PMH = new MH_ptr;
PMH = p->SV.MH_ds.MH_HEAD;
while (PMH != NULL)
{
cout << "" << endl;
cout << "Ma mon hoc : " << PMH->MH.mmh << endl;
cout << "Ten mon hoc: " << PMH->MH.tenmh << endl;
cout << "So tin chi : " << PMH->MH.sotc << endl;
cout << "Diem : " << PMH->MH.diem << endl;
PMH = PMH->next;
}
PMH = p->SV.MH_ds.MH_TAIL;
cout << "" << endl;
/PMH->MH.tbc = PMH->MH.td / PMH->MH.tongtc;
cout << "Tong tin chi sinh vien dang ki :" <
void tinhdtb(SV_ptr *&p) {
MH_ptr *mh_ptr = new MH_ptr;
mh_ptr = p->SV.MH_ds.MH_HEAD;
float sum = 0;
int tongtc = 0;
int diemtb;
while (mh_ptr != NULL)
{
sum += mh_ptr->MH.diem * mh_ptr->MH.sotc;
tongtc += mh_ptr->MH.sotc;
mh_ptr = mh_ptr->next;
}
p->SV.tongtc = tongtc;
p->SV.tbc = sum / tongtc;
}`
` // DSLK QLSV 3.cpp : This file contains the 'main' function. Program execution begins and ends there. //
using namespace std;
//cau truc mon hoc struct MONHOC { char mmh[9]; char tenmh[50]; int sotc; float diem;
};
//cau truc 1 node trong danh sach mon hoc typedef struct MH_node MH_ptr; struct MH_node { MONHOC MH; MH_ptr *next; };
//cau truc danh sach mon hoc typedef struct MH_ds DSMH_ptr; struct MH_ds { int MH_numnode; MH_ptr MH_HEAD, MH_TAIL; };
// cau truc sinh vien struct SINHVIEN { char Mssv[10]; char Hoten[35]; int ngay, thang, nam; DSMH_ptr MH_ds; int tongtc; float tbc; };
// cau truc mot node trong danh sach sinh vien typedef struct SV_node SV_ptr; struct SV_node { SINHVIEN SV; SV_ptr next; }; // cau truc danh sach sinh vien typedef struct SV_ds DSSV_ptr; struct SV_ds { int SV_numnode; SV_ptr SV_head, SV_tail; }; void taoDSMH(SV_node &p); void taoDSSV(DSSV_ptr &List); void taoTemp(DSSV_ptr &List); void nhapMH(SV_ptr &MH_newnode); void nhapSV(DSSV_ptr &List); void insv(SV_ptr P); void Output(DSSV_ptr List);//xuat danh sach; void Output2(SV_ptr p); void tinhdtb(SV_ptr &p); void lietkemax(DSSV_ptr List); float maxdtb(DSSV_ptr List); void timX(DSSV_ptr List, char a[]); void delHead(DSSV_ptr &List); void delTail(DSSV_ptr &List); void XoaNode(DSSV_ptr &List, SV_node q); void xoatheoma(DSSV_ptr &List, char x[]); void AddHead(DSSV_ptr &List, SV_ptr P); void AddTail(DSSV_ptr &List, SV_ptr P); void QuickSort(DSSV_ptr &List); void SelectionSort(DSSV_ptr &List); void SelectionSort2(DSSV_ptr &List); void tachten(SV_ptr p, char hoten[]); int main() {
DSSV_ptr *List = new DSSV_ptr;
taoDSSV(List);
int n;
cout << "Nhap so sinh vien can luu thong tin : ";
cin >> n;
for (int i = 0; i < n; i++)
{
cout << "Nhap thong tin sinh vien thu " << i+1 << " : " << endl;
nhapSV(List);
}
char tieptuc;
cout << endl << "Nhap them sinh vien ? [Y/N]" << endl;
cin >> tieptuc;
cout << tieptuc << endl;
while (tieptuc == 'Y' || tieptuc == 'y')
{
cout << tieptuc << endl;
nhapSV(List);
cout << endl << "Nhap them sinh vien ? [Y/N]" << endl;
cin >> tieptuc;
}
cout << List->SV_head->SV.Hoten << endl;
cout << List->SV_tail->SV.Hoten << endl;
Output(List);
cout << endl << endl;
/*lietkemax(List);
cout << endl << endl;
char a[10];
cout << "Nhap MSSV cua sinh vien muon tim thong tin :" << endl;
cin.ignore();
cin.getline(a, 10);
timX(List, a);
char x[10];
cout << "Nhap MSSV da thoi hoc : " << endl;
cin.ignore();
cin.getline(x, 10);
xoatheoma(List, x);*/
cout << "Danh sach sinh vien sau khi sap xep theo DTB"<<endl;
SelectionSort2(List);
Output(List);
} void taoDSMH(SV_node &p) { p->SV.MH_ds.MH_numnode = 0; p->SV.MH_ds.MH_HEAD = NULL; p->SV.MH_ds.MH_TAIL = NULL; } void taoDSSV(DSSV_ptr &List) { List->SV_head = NULL; List->SV_tail = NULL; List->SV_numnode = 0;
} void taoTemp(DSSV_ptr &List) { List->SV_head = NULL; List->SV_tail = NULL; List->SV_numnode = 0; SV_ptr p; taoDSMH(p);
} void nhapMH(SV_ptr &MH_newnode) { int temp = 1; MH_ptr p = new MH_ptr; p->next = NULL; p->MH.sotc = 0;
if (MH_newnode->SV.MH_ds.MH_numnode > 0)
{
MH_newnode->SV.MH_ds.MH_TAIL->next = p;
MH_newnode->SV.MH_ds.MH_TAIL = p;
}
else
{
p->next = MH_newnode->SV.MH_ds.MH_HEAD;
MH_newnode->SV.MH_ds.MH_HEAD = p;
MH_newnode->SV.MH_ds.MH_TAIL = p;
}
cin.ignore();
cout << " " << temp << ".Ma mon hoc:";
cin.getline(p->MH.mmh, 9);
cout << " Ten mon hoc:";
cin.getline(p->MH.tenmh, 50);
cout << " So tin chi :";
cin >> p->MH.sotc;
cout << " Diem ";
cin >> p->MH.diem;
temp++;
MH_newnode->SV.MH_ds.MH_numnode++;
}
void nhapSV(DSSV_ptr &List) { SV_ptr SV_newnode = new SV_ptr; SV_newnode->next = NULL; if (List->SV_numnode > 0) { List->SV_tail->next = SV_newnode; List->SV_tail = SV_newnode; } else { SV_newnode->next = List->SV_head; List->SV_head = SV_newnode; List->SV_tail = SV_newnode; } cin.ignore(); cout << "Nhap MSSV :" << endl; cin.getline (SV_newnode->SV.Mssv,10); cout << "Nhap ho ten sinh vien :"; cin.getline(SV_newnode->SV.Hoten, 35); cout << "Nhap ngay/thang/nam sinh :"; cin >> SV_newnode->SV.ngay; cin >> SV_newnode->SV.thang; cin >> SV_newnode->SV.nam; int somh; cout << "Nhap so mon hoc cua sinh vien : "; cin >> somh; taoDSMH(SV_newnode); for (int i = 0; i < somh; i++) { cout << i; cout << "Nhap thong tin mon hoc thu " << i + 1 << " : " << endl; nhapMH(SV_newnode);
}
char tieptuc2;
cout << endl << "Nhap them mon hoc ? [Y/N]" << endl;
cin >> tieptuc2;
cout << tieptuc2 << endl;
while (tieptuc2 == 'Y' || tieptuc2 == 'y')
{
nhapMH(SV_newnode);
cout << endl << "Nhap them mon hoc ? [Y/N]" << endl;
cin >> tieptuc2;
}
List->SV_numnode++;
tinhdtb(SV_newnode);
}
void insv(SV_ptr *P)
{
cout << "----------------------------" << endl;
cout << "Thong tin sinh vien : " << endl;
cout << "MSSV: " << P->SV.Mssv << endl;
cout << "Ten sinh vien : " << P->SV.Hoten << endl;
cout << "Ngay sinh : " << P->SV.ngay << "/" << P->SV.thang << "/" << P->SV.nam << endl;
Output2(P);
cout << "----------------------------" << endl;
cout << "Tong tin chi sinh vien dang ki :" << P->SV.tongtc << endl;
cout << "Diem trung binh cua sinh vien : " << P->SV.tbc << endl;
cout << "" << endl;
}
void Output2(SV_ptr p)
{
MH_ptr PMH = new MH_ptr;
PMH = p->SV.MH_ds.MH_HEAD;
while (PMH != NULL)
{
cout << "" << endl;
cout << "Ma mon hoc : " << PMH->MH.mmh << endl;
cout << "Ten mon hoc: " << PMH->MH.tenmh << endl;
cout << "So tin chi : " << PMH->MH.sotc << endl;
cout << "Diem : " << PMH->MH.diem << endl;
PMH = PMH->next;
}
PMH = p->SV.MH_ds.MH_TAIL;
cout << "" << endl;
/PMH->MH.tbc = PMH->MH.td / PMH->MH.tongtc;
cout << "Tong tin chi sinh vien dang ki :" <
void tinhdtb(SV_ptr *&P) {
MH_ptr *mh_ptr = new MH_ptr;
mh_ptr = P->SV.MH_ds.MH_HEAD;
float sum = 0;
int tongtc = 0;
int diemtb;
while (mh_ptr != NULL)
{
sum += mh_ptr->MH.diem * mh_ptr->MH.sotc;
tongtc += mh_ptr->MH.sotc;
mh_ptr = mh_ptr->next;
}
P->SV.tongtc = tongtc;
P->SV.tbc = sum / tongtc;
delete mh_ptr;
} void lietkemax(DSSV_ptr List) { SV_ptr P = List->SV_head; float max = maxdtb(List); cout << "Nhung hoc sinh co diem trung binh max la: " << endl; while (P != NULL) { if (P->SV.tbc == max) insv(P); P = P->next; } delete P; } float maxdtb(DSSV_ptr List) { SV_ptr P = List->SV_head; float max = P->SV.tbc; while (P != NULL) { if (P->SV.tbc > max) max = P->SV.tbc; P = P->next; } delete P; return max; } void timX(DSSV_ptr List, char a[]) { SV_ptr p = List->SV_head; cout << p->SV.Mssv << endl; cout << "Thong tin cua sinh vien can tim la: " << endl;
while (p != NULL)
{
if (strcmp(p->SV.Mssv, a) == 0)
{
insv(p);
}
p = p->next;
}
delete p;
} void delHead(DSSV_ptr &List) { if (List->SV_head == NULL) cout << "Danh sach rong"; else { SV_ptr P = List->SV_head; if (List->SV_head == List->SV_tail) List->SV_head = List->SV_tail = NULL; else List->SV_head = List->SV_head->next; delete P; } } void delTail(DSSV_ptr &List) { if (List->SV_head == NULL) cout << "Danh sach rong" << endl; else { SV_ptr P = List->SV_tail; if (List->SV_head == List->SV_tail) List->SV_head = List->SV_tail = NULL; else { SV_ptr P = List->SV_head; while (P->next != List->SV_tail) P = P->next; List->SV_tail = P; P->next = NULL; } delete P; } } void XoaNode(DSSV_ptr &List, SV_node q) { SV_ptr P = q->next; if (P == NULL) cout << "Khong xoa duoc!"; else { q->next = P->next; if (P == List->SV_tail) List->SV_tail = q; delete P; } } void xoatheoma(DSSV_ptr &List, char x[]) { SV_ptr P, *q; int dem = 0; P = List->SV_head; q = NULL; while (P != NULL) { if (strcmp(x, P->SV.Mssv) == 0) { dem++; break; }
q = P;
P = P->next;
}
if (q != NULL)
{
if (P != NULL)
{
XoaNode(List, q);
}
}
else
{
List->SV_head = P->next;
delete(P);
if (List->SV_head == NULL) List->SV_tail = NULL;
}
if (dem == 0)
{
cout << "Khong tim dc sinh vien can xoa!" << endl;
}
cout << "Danh sach hoc sinh sau khi xoa: " << endl;
Output(List);
} void AddHead(DSSV_ptr &List, SV_ptr P) { if (List->SV_head == NULL) { List->SV_head = List->SV_tail = P; } else { P->next = List->SV_head; List->SV_head = P; } } void AddTail(DSSV_ptr &List,SV_ptr P) { if (List->SV_head == NULL) { List->SV_head = List->SV_tail = P; } else { List->SV_tail->next = P; List->SV_tail = P; } } /void QuickSort(DSSV_ptr &List) { DSSV_ptr L1,L2 = new DSSV_ptr; SV_ptr tag, p; if (List->SV_head == List->SV_tail) return; taoDSSV(L1); taoDSSV(L2); tag = List->SV_head; List->SV_head = List->SV_head->next; tag->next = NULL; while (List->SV_head != NULL) { p = List->SV_head; List->SV_head = List->SV_head ->next; p->next = NULL; if (p->SV.tbc <= tag->SV.tbc) AddHead(L1, p); else AddHead(L2, p); } QuickSort(L1); QuickSort(L2); if (L1->SV_head != NULL) { List->SV_head = L1->SV_head; L1->SV_tail->next = tag; } else List->SV_head = tag; tag->next = L2->SV_head; if (L2->SV_head != NULL) List->SV_tail = L2->SV_tail; else List->SV_tail = tag; }/ void SelectionSort(DSSV_ptr &List) { SV_ptr p, q, min; p = List->SV_head; SINHVIEN temp; while (p != List->SV_tail) { min = p; q = p->next; while (q != NULL) { if (q->SV.tbc < min->SV.tbc) min = q; q = q->next; } temp = p->SV; p->SV = min->SV; min->SV = temp; p = p->next; } } void SelectionSort2(DSSV_ptr &List) { SV_ptr p, q, min; p = List->SV_head; SINHVIEN temp; while (p != List->SV_tail) { min = p; q = p->next; while (q != NULL) { char t1[35]; char t2[35]; tachten(q, t1); tachten(min, t2); cout << t1 << t2; if (strcmp(t1,t2) > 0) min = q; q = q->next; } temp = p->SV; p->SV = min->SV; min->SV = temp; p = p->next; } } void tachten(SV_ptr p,char hoten[]) { strcpy_s(p->SV.Hoten, hoten); char ten[35]; for (int i = strlen(hoten); i >= 0; i--) { if (hoten[i] == ' ') { strcpy_s(ten, hoten + i + 1); } } return; }`
Kế-hoạch.xlsx