package two; import java.util.Scanner; public class LRU { public static void main(String[] args) { int l=0; Integer []now=new Integer[5]; // System.out.print(now[2]); System.out.println("输入多少个数值:"); Scanner in=new Scanner(System.in); int count=in.nextInt(); int []a=new int[count]; System.out.println("输入他们"); for(int i=0;i<count;i++){ a[i]=in.nextInt(); } boolean linshi=true; for(int i=0;i<count;i++){ for(int j=0;j<l;j++){ if(now[j]==a[i]){ for(int o=j;o>0;o--){ now[o]=now[o-1]; } now[0]=a[i]; linshi=false; break; } } if(linshi){ for(int j=0;j<5;j++) if(now[j]==null){ for(int o=j;o>0;o--) now[o]=now[o-1]; now[0]=a[i]; linshi=false; l++; break; } } if(linshi){ System.out.println("删除的值是"+now[4]); for(int j=4;j>0;j--){ now[j]=now[j-1]; } now[0]=a[i]; } for(int j=0;j<now.length;j++){ if(now[j]!=null){ System.out.print(now[j]+" "); } } System.out.println(); linshi=true; } } // }
时间: 2024-11-08 19:22:36