Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void add(Listable itemToAdd) {
- Listable[] list = new Listable[items.length + 1]; // creates a new deep copy
- for (int i=0; i<items.length; i++){
- list[i] = items[i];
- }
- for (int i=0; i<list.length; i++){ // loops through the copy to see if the new item is larger or smaller than the index
- if (itemToAdd.getKeyValue() > list[i].getKeyValue()){ // if the new item is larger:
- list[i] = itemToAdd; // set the new item equal to that index
- }
- else { // if the new item is not larger:
- list[i] = list[i]; // the index value remains what it was
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement