Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. AddItem(S)
  2. {
  3.     if (firstItem == null)
  4.         firstItem = lastItem = new Item(S);
  5.     else
  6.     {
  7.         Item sortingItem = firstItem;
  8.         Item newItem = new Item(S);
  9.        
  10.         // Logic for when only 1 item is in the array
  11.         // because while will not run in this case
  12.  
  13.         while(sortingItem.hasNext())
  14.         {
  15.             if (sortingItem.compareTo(newItem) < 0)
  16.             {
  17.                 newItem.setPrevious(sortingItem.previous);
  18.                 sortingItem.setPrevious(newItem);
  19.                 newItem.setNext(sortinItem);
  20.                 if(newItem.previous = null)
  21.                     firstItem = newItem;
  22.                 else
  23.                     newItem.previous.setNext(newItem);
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement