Packageboth ;ImportJava.util.Scanner; Public classLRU { Public Static voidMain (string[] args) {intL=0; Integer []now=NewInteger[5];//System.out.print (now[2]);System.out.println ("Enter Number of values:"); Scanner in=NewScanner (system.in); intCount=In.nextint (); int[]a=New int[Count]; System.out.println ("Enter them"); for(inti=0;i<count;i++) {A[i]=In.nextint (); } BooleanLinshi=true; for(inti=0;i<count;i++){ for(intj=0;j<l;j++){ if(now[j]==A[i]) { for(into=j;o>0;o--) {Now[o]=now[o-1]; } now[0]=A[i]; Linshi=false; Break; } } if(Linshi) { for(intj=0;j<5;j++) if(now[j]==NULL){ for(into=j;o>0;o--) Now[o]=now[o-1]; now[0]=A[i]; Linshi=false; L++; Break; } } if(Linshi) {System.out.println ("The deleted value is" +now[4]); for(intj=4;j>0;j--) {Now[j]=now[j-1]; } now[0]=A[i]; } for(intj=0;j<now.length;j++){ if(now[j]!=NULL) {System.out.print (Now[j]+" "); }} System.out.println (); Linshi=true; } }//}
LRU algorithm Simple implementation