阿里巴巴2022校招软件笔试题经典(含答案).docx
上传者:森森
2022-05-25 08:50:47上传
DOCX文件
17 KB
阿里巴巴2022校招软件笔试题经典(含答案)
阿里巴巴2022校招软件笔试题经典
1、写一个函数,输入一个二叉树,树中每个节点存放了一个整数值,函数返回这棵二叉树中相差最大的两个节点间的差值绝对值。请注意程序效率。
int Max(bitree * root)
{ if(root==NULL)return 0;
else{ if(root->data>max)
max=root->data;
Max(root->lchild);
Max(root->rchild);
}
return max;
}
int Min(bitree * root)
{ if(root==NULL)return 0;
else{ if(root->datadata;
M(root->lchild);
M(root->rchild);
}
return min;
}
int main()
{ bitree *root;
root=creatbitree();
printf("最大值与最小值之差为:\n");
printf("%d",abs(Max(root)-Min(root)));
return 0;
}
2、给定一个query和一个text,均由小写字母组成。要求在text中找出以同样的顺序连续出现在query中的最长连续字母序列的长度。例如,query为“acbac”,text为“acaccbabb”,那么text中的“cba”为最长的连续出现在query中的字母序列,因此,返回结果应该为其长度3。请注意程序效率。
#include "stdio.h"
#include "string.h"
#define N 101
阿里巴巴2022校招软件笔试题经典
1、写一个函数,输入一个二叉树,树中每个节点存放了一个整数值,函数返回这棵二叉树中相差最大的两个节点间的差值绝对值。请注意程序效率。
int Max(bitree * root)
{ if(root==NULL)return 0;
else{ if(root->data>max)
max=root->data;
Max(root->lchild);
Max(root->rchild);
}
return max;
}
int Min(bitree * root)
{ if(root==NULL)r
阿里巴巴2022校招软件笔试题经典
1、写一个函数,输入一个二叉树,树中每个节点存放了一个整数值,函数返回这棵二叉树中相差最大的两个节点间的差值绝对值。请注意程序效率。
int Max(bitree * root)
{ if(root==NULL)return 0;
else{ if(root->data>max)
max=root->data;
Max(root->lchild);
Max(root->rchild);
}
return max;
}
int Min(bitree * root)
{ if(root==NULL)return 0;
else{ if(root->datadata;
M(root->lchild);
M(root->rchild);
}
return min;
}
int main()
{ bitree *root;
root=creatbitree();
printf("最大值与最小值之差为:\n");
printf("%d",abs(Max(root)-Min(root)));
return 0;
}
2、给定一个query和一个text,均由小写字母组成。要求在text中找出以同样的顺序连续出现在query中的最长连续字母序列的长度。例如,query为“acbac”,text为“acaccbabb”,那么text中的“cba”为最长的连续出现在query中的字母序列,因此,返回结果应该为其长度3。请注意程序效率。
#include "stdio.h"
#include "string.h"
#define N 101
阿里巴巴2022校招软件笔试题经典
1、写一个函数,输入一个二叉树,树中每个节点存放了一个整数值,函数返回这棵二叉树中相差最大的两个节点间的差值绝对值。请注意程序效率。
int Max(bitree * root)
{ if(root==NULL)return 0;
else{ if(root->data>max)
max=root->data;
Max(root->lchild);
Max(root->rchild);
}
return max;
}
int Min(bitree * root)
{ if(root==NULL)r