c++二叉树 用代码把逻辑图(二叉树的图) 画出来。求帮忙

输出效果就是二叉树的逻辑图像
2025-05-12 00:04:03
推荐回答(1个)
回答1:

#include"stdio.h"#include"stdlib.h"#include"string.h"#include"conio.h"#include"malloc.h"typedefstruct_student{charnumber[20];charname[20];intscore;}Student;typedefstruct_node{Studentstudent;_node*lchild,*rchild;}Node,*PNode,BSTree,*PBSTree;voidBSTreeInsert(PBSTree*root,Students){if(*root==NULL){*root=(PBSTree)malloc(sizeof(BSTree));strcpy((*root)->student.number,s.number);strcpy((*root)->student.name,s.name);(*root)->student.score=s.score;(*root)->lchild=NULL;(*root)->rchild=NULL;return;}elseif(s.scorestudent.score)BSTreeInsert(&((*root)->lchild),s);elseBSTreeInsert(&((*root)->rchild),s);}voidInOrder(PBSTreeroot){if(!root)return;InOrder(root->lchild);printf("%s\t%s\t%d\n",root->student.number,root->student.name,root->student.score);InOrder(root->rchild);}voidmain(){inti,j,n,_class;PBSTreebstree[20];Students;for(i=0;i<20;i++)bstree[i]=NULL;printf("请输入班级数!\n");scanf("%d",&_class);for(j=0;j<_class;j++){printf("请输入%d班的学生人数!\n",j+1);scanf("%d",&n);printf("请输入学生信息:学号姓名成绩\n");for(i=0;i