Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void insertLink(String n, String l, String s, int i) {
- Link curLink = first;
- Link temp = new Link(n, l, s, i);
- //if there are no links, inserts to front
- if (isEmpty()) {
- first = new Link(n, l, s, i);
- last = first;
- highest = first.age;
- } else { //if link is highest age, puts it in last position
- if (i > highest) {
- insertLast(n, l, s, i);
- highest = i;
- } else if (i < first.age) { //if link is lowest age puts it in front
- temp.next = first;
- first.prev = temp;
- first = temp;
- } else {
- while (curLink != null) { //if link belongs
- if (i < curLink.age) {
- curLink.prev.next = temp;
- temp.prev = curLink.prev;
- curLink.prev = temp;
- temp.next = curLink;
- break;
- } else {
- curLink = curLink.next;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement