java - how to insert an element into an order array -
Say I have an array of interses that are sorted in ascending order, and I want to enter a new number And I know how to put the position on it but how can I use the system. Arequipi
System ArrayCopy (items, I, items, I + 1, items. Length + 1); Item [i] = n; Or I need to create a temporary array copy of the entry for the temporary array (position move an element), and then copy back to the original array
int [] newItems = new int [size + 1]; System ArrayCopy (items, I, new items, I + 1, items length + 1); Item [i] = s; Size ++; System ArrayCopy (items, 0, new items, I, I); Item = new item;
Your first method will work.
If you are not sure, see the documentation on Arakopi. If the source and destination are the same, then it will work as if it is copied to a temporary array that is then copied to the original array, so you can be confident that this will work!
Comments
Post a Comment