gpt4 book ai didi

搜索整个二叉树后比较值

转载 作者:太空宇宙 更新时间:2023-11-04 06:12:26 24 4
gpt4 key购买 nike

<分区>

我的二叉树运行良好。但是,我正在尝试将用户输入与二进制文件进行比较,以检查它们是否匹配。但是,当我检查输入时,它会在 btree 的每个子节点上打印出“没有那个名字的学生”。

有没有办法在我不匹配时只打印一次,而在匹配时不打印? [也许我必须等到二叉树停止运行,但我不知道]

我的项目包含一个包含学生姓名的文本文件。我想知道是否有更简单的方法来搜索文件并将其与用户输入的字符串进行比较,而不是在 btree 中搜索。

C:\Users\dd\c-eclipse-workspace\Code\src>database namesids.txt marks.txt Enter command: FN Enter name to search:FREE There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.There is no student with that name.

void searchTreeID(struct StudentRecord* root, int id){
// if there is left tree traverse left
// printf("123");
if(root->left != NULL){
searchTreeID(root->left, id);
}
if(root->ID==id){
// print the middle
printf("Student Name%s",root->first);
printf(" %-10s\n",root->last);
printf("Student ID %10d\n",root->ID);
printf("Total Grade %15d\n",root->marks);

} // if there is right tree traverse right
else{
printf("There is no student with that ID.\n");
}
if(root->right != NULL){

searchTreeID(root->right,id);
}
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com