SHOW:
|
|
- or go back to the newest paste.
1 | public class DoubleLinkedListOrdenada <ELEMENT extends Comparable<ELEMENT>> | |
2 | extends DoubleLinkedList<ELEMENT>implements LinkedListOrdenada<ELEMENT>{ | |
3 | ||
4 | public DoubleLinkedListOrdenada () {super(); } | |
5 | ||
6 | ||
7 | public void addenOrden(ELEMENT item){ | |
8 | if(this.size()==0) { | |
9 | this.head=this.tail = new Node<ELEMENT>(item, null, null); | |
10 | ++this.count; | |
11 | }else { | |
12 | if(item.compareTo(this.head.item) <= 0){ | |
13 | this.addFirst(item); | |
14 | }else { | |
15 | if(item.compareTo(this.tail.item)> 0) { | |
16 | this.addLast(item); | |
17 | }else { | |
18 | Node<ELEMENT> skip= this.head; | |
19 | while((skip!=null)&&(item.compareTo(skip.item)>0)) { | |
20 | skip=skip.next; | |
21 | } | |
22 | if(skip==null){ | |
23 | throw new RuntimeException("Algo Esta Raro en el orden de los elementos de la lista..."); | |
24 | } | |
25 | else { | |
26 | Node<ELEMENT> temp= new Node<>(item,skip,skip.prev); | |
27 | skip.prev.next=temp; | |
28 | skip.prev=temp; | |
29 | ++ this.count; | |
30 | } | |
31 | } | |
32 | } | |
33 | } | |
34 | } | |
35 | ||
36 | } | |
37 |