public class newSolut { static int leIndex = 1; static boolean[] hasReceive = new boolean[10 + 1 + 1]; static int[] nums = { 2, 1, 4, 5, 7, 3, 9, 8, 6, 10 }; public static void main(String[] args) { for (int i = 0; i < nums.length; i++) { System.out.println("现在消息流是:" + nums[i]); receive(nums[i]); } } public static void receive(int num) { if (num == leIndex) { if (hasReceive[leIndex] == false) { System.out.println(leIndex); hasReceive[leIndex] = true; leIndex++; while (hasReceive[leIndex] == true) { System.out.println(leIndex); leIndex++; } } } else { hasReceive[num] = true; } } }
点赞 3

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务