Professional Documents
Culture Documents
Chinh Ham Red Cac Ham Khac Tung Tu
Chinh Ham Red Cac Ham Khac Tung Tu
Mục lục
1 Chỉnh code hàm RED 3
1.1 bước 1 và 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 bước 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Bước 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 Bước 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.5 Bước 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 Bước 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.7 Tóm lại . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
• bước 2 có thể xét trong hàng đợi thôi vì trong hàng đợi có khách thì trong bàn đầy
1.2 bước 3
Code mẫu 1 :
1 //* Bước 3 "thiên thượng thiên hạ, duy ngã độc tôn" : chung tên đuổi về
2 else
3 {
4 //TODO : xem thử khác hàng dùng bữa có chung tên không
5 customer* temp = customerX;
6 for(int i = 0; i < sizeCustomerInDesk; i++)
7 {
8 if(temp->name == name) return;
9 temp = temp->next;
10 }
11
12 //TODO : xem thử khác hàng đang chờ có chung tên không
13 temp = customerQueue;
14 for(int i = 0; i < sizeCustomerQueue; i++)
15 {
16 if(temp->name == name) return;
17 temp = temp->next;
18 }
19 }
20
Code mẫu 2 :
1 //* Bước 3 "thiên thượng thiên hạ, duy ngã độc tôn" : chung tên đuổi về
2 else
3 {
4 customerTime* temp = CustomerTimeHead;
5 //* xem thử khác hàng có chung tên không với khách nào hay không
6 for(int i = 0; i < sizeCustomerInDesk + sizeCustomerQueue; i++)
7 {
8 //TODO tìm thử trung tên không
9 if(temp->data->name == name) return;
10 temp = temp->next;
11 }
12 }
1 bool checkCustomerSameName()
2 {
3 // code
4 return false;
5 }
1 ;
2 //* xem thử khác hàng có chung tên không với khách nào hay không
3 for(customerTime* temp = CustomerTimeHead; temp != nullptr; temp = temp->next)
4 {
5 //TODO tìm thử trung tên không
6 if(temp->data->name == name) return;
7 temp = temp->next;
8 i ++;
9 }
• có thể chỉnh head thành tail để duyệt lại theo chiều prev
• có thể đảo với bước 4, 5
1.3 Bước 4
Code mẫu : đọc trong code đi nha dài quá anh không ghép vô
1 if(sizeCustomerQueue == 0)
2 {
3 customer* newCustomer = new customer(name, energy, nullptr, nullptr);
4 customerQueue = newCustomer;
5 customerQueue->next = customerQueue->prev = newCustomer;
6 customerTime* newCustomerTime = new customerTime (newCustomer, false);
7 CustomerTimeTail->next = newCustomerTime;
8 newCustomerTime->prev = CustomerTimeTail;
9 CustomerTimeTail = newCustomerTime;
10 return;
11 }
12 customer* newCustomer = new customer(name, energy, nullptr, nullptr);
13 newCustomer->next = customerQueue; //! cập nhật thằng mới vô
14 newCustomer->prev = customerQueue->prev; //! cập nhật thằng mới vô
15 customerQueue->prev = newCustomer->prev->next = newCustomer;
16 //& cập nhật số lượng khách nhà hàng
17 sizeCustomerQueue ++;
18
19
6 {
7 //TODO thêm vào sau khách hàng đầu tiên (thêm vào cuối) dùng next
8 }
1 bool insertCustomerQueue()
2 {
3 // code
4 return false;
5 }
1.4 Bước 5
• customerX = new customer (name, energy, nullptr, nullptr); có thể đưa ra ngoài gộp chung bước
dưới
• customerX->next = customerX->prev = customerX;); tác ra làm 2 bước
• tác ra hàm riêng
1.5 Bước 6
• chỉnh while for giống bước 3
1.6 Bước 7
• đảo bước thêm sau lên trước.
• tác ra hàm riêng