代码求调
  • 板块学术版
  • 楼主Mumu_3
  • 当前回复8
  • 已保存回复8
  • 发布时间2023/2/21 19:55
  • 上次更新2023/10/24 00:09:34
查看原帖
代码求调
586329
Mumu_3楼主2023/2/21 19:55

rt,题目不在本站,附个链接:题目地址

能帮倒忙的话就太感谢了

#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;
}
``
2023/2/21 19:55
加载中...