资源描述:
《亚信校招笔试题目.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、.1.BSTpublicclassBSTMinLength{publicstaticvoidmain(String[]args){TreeNodetNode11=newTreeNode(10,null,null);TreeNodetNode12=newTreeNode(50,null,null);TreeNodetNode13=newTreeNode(5,null,null);TreeNodetNode14=newTreeNode(30,null,null);TreeNodetNode21=newTreeNode(30,tNode1
2、1,tNode12);TreeNodetNode22=newTreeNode(30,tNode13,tNode14);TreeNodetNodeRoot=newTreeNode(100,tNode21,tNode22);System.out.println(minlength(tNodeRoot));}privatestaticintminlength(TreeNodetNode){if(tNode!=null){returngetlength(tNode,0);}return-1;}privatestaticintgetlengt
3、h(TreeNodetNode,intcurLength){intminLeft=-1;intminRight=-1;if(tNode.leftNode!=null){minLeft=getlength(tNode.leftNode,curLength+tNode.value);}if(tNode.rightNode!=null){minRight=getlength(tNode.rightNode,curLength+tNode.value);}if(tNode.leftNode==null&&tNode.rightNode==n
4、ull){..returncurLength+tNode.value;}if(tNode.leftNode==null){returnminRight;}if(tNode.rightNode==null){returnminLeft;}returnminLeft>minRight?minRight:minLeft;}}classTreeNode{intvalue;TreeNodeleftNode;TreeNoderightNode;TreeNode(intvalue,TreeNodelefeNode,TreeNoderightNod
5、e){this.value=value;this.leftNode=lefeNode;this.rightNode=rightNode;}}2.lru#includeusingnamespacestd;intlruCountMiss(intmax_cache_size,int*pages,intlen){intcount=0;inti,j,k,n;boolflag=false;..int*a=newint[max_cache_size];//初始化高速缓存数组for(i=0;i6、+){a[i]=-1;}for(j=0;j7、j];}else{flag=false;for(n=i;n8、ount;}intmain(){intarr[]={7,0,1,2,0,3,0,4};cout<