Tôi có chức năng truyền tải đặt hàng trước như sau:
void listInPreOrder(node* hd){
if(hd != NULL) {
printf("%d,", hd->value);
listInPreOrder(hd->left);
listInPreOrder(hd->right);
}
}
Cái này thực sự hiệu quả nhưng tôi nghĩ làm nó sau khi đặt hàng sẽ đơn giản như thế này
void listInPostOrder(node* hd){
if(hd != NULL) {
listInPreOrder(hd->left);
listInPreOrder(hd->right);
printf("%d,", hd->value);
}
}
Nhưng thật không may, nó không hoạt động tốt như vậy. Tôi đang tự hỏi làm thế nào để giải quyết vấn đề này, có lẽ tôi đang làm sai điều gì đó đơn giản. Hoặc có thể nó chỉ đơn giản là sai.
Làm thế nào bạn thay đổi điều này:
void listInPostOrder(node* hd){
if(hd != NULL) {
listInPreOrder(hd->left); // Đặt hàng TRƯỚC ???
listInPreOrder(hd->right); // Đặt hàng TRƯỚC ???
printf("%d,", hd->value);
}
}
để kết thúc này:
void listInPostOrder(node* hd){
if(hd != NULL) {
listInPostOrder(hd->left);
listInPostOrder(hd->right);
printf("%d,", hd->value);
}
}
Tôi là một lập trình viên xuất sắc, rất giỏi!