Ejemplo n.º 1
0
 public LinkedList prepend(LinkedList r) {
   r.prev = this.prev;
   r.next = this;
   if (this.prev != null) this.prev.next = r;
   this.prev = r;
   return r;
 }
Ejemplo n.º 2
0
 public LinkedList insert(LinkedList r) {
   r.prev = this;
   r.next = this.next;
   if (this.next != null) this.next.prev = r;
   this.next = r;
   return r;
 }
Ejemplo n.º 3
0
 public LinkedList append(LinkedList r) {
   LinkedList p = this;
   r.next = null;
   while (p.next != null) p = p.next;
   p.next = r;
   return (r.prev = p);
 }
  public static LinkedList reverseQueue(LinkedList head) {
    LinkedList current = head;
    if (current == null) {
      return null;
    }
    LinkedList next = current.next;

    if (next == null) {
      head = current;
      return head;
    }

    head = reverseQueue(next);
    next.next = current;
    current.prev = next;
    next.prev = null;
    current.next = null;
    return head;
  }
Ejemplo n.º 5
0
 public LinkedList detach() { // returns new head relative to this node
   LinkedList p = prev, n = next;
   if (this == first()) {
     if (n != null) n.prev = null;
     next = null;
     return n;
   }
   if (this == last()) {
     if (p != null) p.next = null;
     prev = null;
     return p;
   }
   prev = null;
   next = null;
   //		if (p == null && n == null) return null;
   if (p != null) p.next = n;
   if (n != null) n.prev = p;
   if (p == null) return n;
   else return p.first();
 }
Ejemplo n.º 6
0
 public void eraseList() {
   LinkedList t;
   LinkedList f = first();
   t = f.next;
   f.next = null; // remove references
   while (t != null) {
     f = t.next;
     t.prev = null;
     t.next = null;
     t = f;
   }
   ;
 }
Ejemplo n.º 7
0
 public LinkedList cloneList() {
   LinkedList t;
   LinkedList f = first();
   LinkedList k = (LinkedList) f.clone();
   LinkedList nf = k;
   while (f.hasMoreElements() != false) {
     f = (LinkedList) f.nextElement();
     t = (LinkedList) f.clone();
     t.prev = k;
     k.next = t;
     k = t;
   }
   ;
   return nf;
 }
Ejemplo n.º 8
0
 public LinkedList allBut(Object key) {
   LinkedList t;
   LinkedList f = first();
   if (f.value.equals(key))
     if (f.next != null) f = f.next;
     else return null;
   LinkedList k = (LinkedList) f.clone();
   LinkedList nf = k;
   while (f.hasMoreElements() != false) {
     f = (LinkedList) f.nextElement();
     if (f.value.equals(key)) continue;
     t = (LinkedList) f.clone();
     t.prev = k;
     k.next = t;
     k = t;
   }
   ;
   return nf;
 }