SHARE
TWEET

Untitled

a guest Aug 24th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.kvart;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class Iterator {
  6.  
  7.     private int[][] arr;
  8.     private int[] arrSort;
  9.     private int start = 0;
  10.  
  11.     public Iterator(int[][] arr) {
  12.         this.arr = arr;
  13.  
  14.         int value = 0;
  15.         for (int i = 0; i < arr.length; i++) {
  16.             value += arr[i].length;
  17.         }
  18.         arrSort = new int[value];
  19.         int index = 0;
  20.         for (int i = 0; i < arr.length; i++) {
  21.             for (int j = 0; j < arr[i].length; j++) {
  22.                 arrSort[index] = arr[i][j];
  23.                 index++;
  24.             }
  25.         }
  26.  
  27.         Arrays.sort(arrSort);
  28.  
  29.     }
  30.  
  31.     public boolean hasNext() {
  32.         return start < arrSort.length;
  33.     }
  34.  
  35.     public int next() {
  36.         start ++;
  37.         return arrSort[start - 1];
  38.     }
  39.  
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top