社区讨论
代码求调
学术版参与者 2已保存回复 8
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 8 条
- 当前快照
- 1 份
- 快照标识符
- @lo33fc3c
- 此快照首次捕获于
- 2023/10/24 00:09 2 年前
- 此快照最后确认于
- 2023/10/24 00:09 2 年前
rt,题目不在本站,附个链接:题目地址
能帮倒忙的话就太感谢了

C#include<bits/stdc++.h>
#define EndFlag NULL
using namespace std;
typedef string ElemType;
typedef struct BSTNode{
ElemType data;
int num;
BSTNode* lchild,*rchild;
BSTNode(){
num=0;
}
}BSTNode,*BSTree;
int tot=0;
void InsertBST(BSTree& T,ElemType e){
if(!T){
BSTree S = new BSTNode;
S->data = e;
S->lchild = S->rchild = NULL;
T = S;
T->num++;
}else if(e < T->data){
InsertBST(T->lchild,e);
}else if(e > T->data){
InsertBST(T->rchild,e);
}else if(e == T->data){
T->num++;
}
}
void CreateBST(BSTree& T){
T = NULL;
ElemType e;
while(getline(cin,e)){
InsertBST(T,e);
tot++;
}
}
void inorder(BSTree& T){
if(T){
inorder(T->lchild);
cout<<T->data;
printf(" %0.4lf\n",(T->num*100.0) / (tot*1.0));
inorder(T->rchild);
}
}
int main(){
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
BSTree T;
CreateBST(T);
inorder(T);
return 0;
}
``
回复
共 8 条回复,欢迎继续交流。
正在加载回复...