求求大佬,pta是否同一棵二叉搜索树交上去为什么全是段错误

weixin_44913265 2019-11-09 06:22:33

这是我的代码
#include <iostream>
#include <string.h>
#include <malloc.h>
#include <stdio.h>
using namespace std;
typedef struct node *BinTree;
int n;
struct node{
int data;
BinTree left;
BinTree right;
int flag;
};
void reset(BinTree t);
BinTree insert(BinTree t,int x);
int find(BinTree t,int x);
int jurdge(BinTree t,int temp[]);
BinTree insert(BinTree t,int x){
if(t==NULL){
t=(BinTree)malloc(sizeof(struct node));
t->data=x;
t->flag=0;
t->left=t->right=NULL;
}
else{
if(x>t->data){
t->right=insert(t->right,x);
}
else if(x<t->data){
t->left=insert(t->left,x);
}
}
}
int find(BinTree t,int x){
if(t){
if(x>t->data){
if(t->flag==1){
return find(t->right,x);
}
else{
return 0;
}
}
else if(x<t->data){
if(t->flag==1){
return find(t->left,x);
}
else{
return 0;
}
}
else{
t->flag=1;
return 1;
}
}
else return 0;
}
int jurdge(BinTree t,int b[]){
int i;
for(i=0;i<n;i++){
if(find(t,b[i])==0){
return 0;
}
}
return 1;
}
void reset(BinTree t){
if(t){
t->flag=0;
reset(t->left);
reset(t->right);
}
else{
return ;
}
}
int main(int argc, char** argv) {
int l;
int a[11];
int b[11];
int i;
BinTree t;
while(scanf("%d",&n)!=EOF){
t=NULL;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
if(n==0){
return 0;
}
scanf("%d",&l);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
t=insert(t,a[i]);
}
while(l-->0){
reset(t);
for(i=0;i<n;i++){
scanf("%d",&b[i]);
}
if(jurdge(t,b)==1){
printf("Yes\n");
}
else{
printf("No\n");
}
}
}
return 0;
}
...全文
100 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Italink 2019-11-09
  • 打赏
  • 举报
回复
段错误是因为访问越界,检查一下哪里出错了
wowpH 2019-11-09
  • 打赏
  • 举报
回复
引用 1 楼 weixin_44913265 的回复:
做过pta这道题的大佬帮忙看看啊
不知道这是哪道题。 CSDN论坛新手指南
weixin_44913265 2019-11-09
  • 打赏
  • 举报
回复
做过pta这道题的大佬帮忙看看啊

64,639

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧