Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. public void add(Listable itemToAdd) {
  2. Listable[] list = new Listable[items.length + 1]; // creates a new deep copy
  3. for (int i=0; i<items.length; i++){
  4. list[i] = items[i];
  5. }
  6.  
  7. 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
  8. if (itemToAdd.getKeyValue() > list[i].getKeyValue()){ // if the new item is larger:
  9. list[i] = itemToAdd; // set the new item equal to that index
  10. }
  11. else { // if the new item is not larger:
  12. list[i] = list[i]; // the index value remains what it was
  13. }
  14. }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement