亚信校招笔试题目
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
public class BSTMinLength {
public static void main(String[] args) {
TreeNode tNode11 = new TreeNode(10, null, null);
TreeNode tNode12 = new TreeNode(50, null, null);
TreeNode tNode13 = new TreeNode(5, null, null);
TreeNode tNode14 = new TreeNode(30, null, null);
TreeNode tNode21 = new TreeNode(30, tNode11, tNode12);
TreeNode tNode22 = new TreeNode(30, tNode13, tNode14);
TreeNode tNodeRoot = new TreeNode(100, tNode21, tNode22); }
private static int minlength(TreeNode tNode)
{
if (tNode != null) {
return getlength(tNode,0);
}
return -1;
}
private static int getlength(TreeNode tNode,int curLength) {
int minLeft=-1;
int minRight=-1;
if !=null){
minLeft=getlength, curLength+;
}
if !=null) {
minRight=getlength, curLength+;
}
if ==null && ==null) {
return curLength+;
}
if ==null) {
return minRight;
}
if ==null) {
return minLeft;
}
return minLeft>minRight minRight:minLeft;
}
}
class TreeNode {
int value;
TreeNode leftNode;
TreeNode rightNode;
TreeNode(int value, TreeNode lefeNode, TreeNode rightNode) { = value;
= lefeNode;
= rightNode;
}
}
#include
using namespace std;
int lruCountMiss(int max_cache_size, int *pages, int len) {
int count = 0;
int i,j,k,n;
bool flag = false;
int *a = new int[max_cache_size];
转链表
lnode *reverse(lnode *head){
if(head){
lnode *prev = NULL;
lnode *curr = head;
lnode *next = curr->next;
curr->next = prev;
while(next != NULL){
prev = curr;
curr = next;
next = next->next;
curr->next = prev;
}
return curr;
}else{
return head;
}
};
lnode *reverseLinkedList(lnode *list){
if(list){
lnode *ori = list;
lnode *half = list;
lnode *prev = list;
while(list && half && half->next){
prev = list;
list = list->next;
half = half->next;
if(half){
half = half->next;
}
}
if(list){
prev->next = reverse(list);
}
return ori;
}
return list;
}
4. SJF
float waitingTimeSJF(int * requestTimes, int * durations,int n){ int *flags = new int[n];
for(int i = 0 ;i< n; i++){
flags[i] = -1;
}
int nowtime = 0;
for( int i = 0; i< n; i++ ){
int count = 0;
for(int k = 0; k< n;k++){
if(count == 0){
if(requestTimes[k] <= nowtime && durations[k] >=0 ){ flags[count++] = k;
}
}
else{
if(durations[k] >=0 && requestTimes[k] <= nowtime ){ if( durations[k] < durations[flags[0]]){
count = 1;
flags[0] = k;
}else if( durations[k] == durations[flags[0]] ){
flags[count++] = k;
}
}
}
}
if(count == 0){