Jūs esate

number insert

Įrašų įterpimas į surikiuotą masyvą

private static void insertEntryIntoArray(int insertationIndex, int entry, int [] array) { for (int i = array.length - 1; i > insertationIndex; i--) array[i] = array[i - 1]; array[insertationIndex] = entry; } // Kodas.... int [] array = new int[5]; int numberToInsert = 7; int entriesFilled = 3; array[0] = 1; array[1] = 5; array[2] = 10; for (int i = 0; i < entriesFilled; i++) if (array[i] > numberToInsert) { insertEntryIntoArray(i, numberToInsert, array); entriesFilled++; break; } Gal kam pravers :)
Subscribe to number insert