Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public void insertLink(String n, String l, String s, int i) {
  2. Link curLink = first;
  3. Link temp = new Link(n, l, s, i);
  4. //if there are no links, inserts to front
  5. if (isEmpty()) {
  6. first = new Link(n, l, s, i);
  7. last = first;
  8. highest = first.age;
  9. } else { //if link is highest age, puts it in last position
  10. if (i > highest) {
  11. insertLast(n, l, s, i);
  12. highest = i;
  13. } else if (i < first.age) { //if link is lowest age puts it in front
  14. temp.next = first;
  15. first.prev = temp;
  16. first = temp;
  17. } else {
  18. while (curLink != null) { //if link belongs
  19. if (i < curLink.age) {
  20. curLink.prev.next = temp;
  21. temp.prev = curLink.prev;
  22. curLink.prev = temp;
  23. temp.next = curLink;
  24. break;
  25. } else {
  26. curLink = curLink.next;
  27. }
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement