Код: Выделить всё
struct DauSach {
char ISBN[MAX_ISBN + 1];
char tensach[MAX_TENSACH + 1];
int sotrang;
char tacgia[MAX_TACGIA + 1];
int nxb;
char theloai[MAX_THELOAI + 1];
PtrSach* First = nullptr;
int soluotmuon;
int soluong;
DauSach() {
}
DauSach(char* isbn, char* ten, int st, char* tg, int xb, char* tl) {
strcpy(ISBN, isbn);
strcpy(tensach, ten);
sotrang = st;
strcpy(tacgia, tg);
nxb = xb;
strcpy(theloai, tl);
First = nullptr;
soluong = 0;
soluotmuon = 0;
}
};
struct DS_DauSach {
int n;
DauSach* nodes[MAX_SIZE_DAUSACH];
DS_DauSach() {
n = 0;
}
~DS_DauSach() {
while (n) {
DeleteAllPtrSach(nodes[n - 1]->First);
delete nodes[--n];
}
}
};
Код: Выделить всё
struct Sach {
char MASACH[MAX_MASACH + 1];
int trangthai;
char vitri[MAX_VITRI + 1];
Sach() {
}
Sach(char ms[MAX_MASACH + 1], int tt, char vt[MAX_VITRI + 1]) {
strcpy(MASACH, ms);
trangthai = tt;
strcpy(vitri, vt);
}
};
// NODE Sach - DSLK don
struct PtrSach {
Sach sach;
PtrSach* next;
};
Сначала я получаю узел текущей книги с помощью этого кода.
Код: Выделить всё
PtrSach* nodeSelect = GetPtrSach(DSDS.nodes[curDauSach]->First, 10 * (curPageSach - 1) + curSach);
Код: Выделить всё
PtrSach* GetPtrSach(PtrSach* First, int position) {
PtrSach* node = First;
for (int i = 0; node != nullptr; node = node->next) {
if (i == position) {
return node;
}
++i;
}
return nullptr; // Return nullptr if position is out of bounds
}
Код: Выделить всё
XoaPtrSachTheoMaSach(nodeSelect, sach.MASACH);
void XoaPtrSachTheoMaSach(PtrSach*& head, char* targetMASACH) {
if (head == nullptr) return; // Empty list
while (head != nullptr && strcmp(head->sach.MASACH, targetMASACH) == 0) {
PtrSach* tmp = head;
head = head->next;
delete tmp;
}
if (head == nullptr) return;
PtrSach* current = head;
while (current->next != nullptr) {
if (strcmp(current->next->sach.MASACH, targetMASACH) == 0) {
PtrSach* tmp = current->next;
current->next = current->next->next;
delete tmp;
}
else {
current = current->next;
}
}
}
Код: Выделить всё
void DrawDanhMucSach() {
... // these previous part can be ignored
PtrSach* node = GetPtrSach(DSDS.nodes[curDauSach]->First, 10 * (curPageSach - 1));
for (int i = 0; node != nullptr && i < 10; node = node->next) {
DrawItemSach(node->sach, i++);
}
}
Примечание. Нам не разрешено использовать стандартную библиотеку, однако внутри есть строковая библиотека. , который можно использовать только с функцией strcpy или сравнивать char[].
Подробнее здесь: https://stackoverflow.com/questions/792 ... r-while-pr