void bianliTreeNode p char father写入祖先 ofstream wDdzytxt iosapp;追加 if !w cerr file could not be open endl; exit0; TreeNode q; if p左子树的不为空 w father t p-databeifen t p-dataname t p-dat
The function "bianli" takes a pointer to a TreeNode object and a character array representing the name of the father as parameters. It opens a file named "dzy.txt" for appending. If the file cannot be opened, it displays an error message and exits the program.
The function then checks if the pointer p is not null. If p is not null, it writes the information of the current node p into the file, including the father's name, the backup, name, sex, birthday, death day, school, and work. It then recursively calls bianli on the left child of p.
Next, the function assigns the right child of p to a pointer q. It enters a loop that continues as long as q is not null. Inside the loop, it writes the information of the current node q into the file, including the father's name, the backup, name, sex, birthday, death day, school, and work. It then recursively calls bianli on the left child of q. After that, it updates q to the right child of q.
Once the loop ends, the function closes the file
原文地址: https://www.cveoy.top/t/topic/h0Oa 著作权归作者所有。请勿转载和采集!