import java.util.*;

public class CircularLinkedList
{
    public CircularLinkedList ()
    {
        _entries = new HashMap<Integer, Node>();
        _head = _tail = _current = null;
    }

    public final HashMap<Integer, Node> getEntries ()
    {
        return _entries;
    }
    
    public final Set<Integer> asList ()
    {
        return _entries.keySet();
    }

    public final Node getCurrent ()
    {
        return _current;
    }

    public final void setCurrent (Node c)
    {
        _current = c;
    }

    public final void add (int value)
    {
        add(new Node(value));
    }

    public final void add (Node n)
    {
        if (_entries.size() == 0)
        {
            _head = n;
            _tail = _head;
            _current = _head;
            _current.setNext(_head);
        }
        else
        {
            Node last = _tail;

            last.setNext(n);
            n.setNext(_head);
            _tail = n;
        }

        _entries.put(n.getValue(), n);
    }

    public void addTo (Node position, CircularLinkedList toAdd)
    {
        //System.out.println("Position: "+position);

        if (position == _tail)
        {
            Node theTail = _tail;

            _tail = toAdd._tail;
            _tail.setNext(_head);
            theTail.setNext(toAdd._head);
        }
        else
        {
            Node posNext = position.getNext();

            position.setNext(toAdd._head);
            toAdd._tail.setNext(posNext);
        }

        _entries.putAll(toAdd._entries);
    }

    public final CircularLinkedList removeFrom (Node position)
    {
        CircularLinkedList removed = new CircularLinkedList();
        Node cup = position.getNext();
        Node entry = cup;

        removed.add(cup.getValue());
        //System.out.println("added "+cup);

        _entries.remove(cup.getValue());

        for (int i = 0; i < 2; i++)
        {
            entry = entry.getNext();

            removed.add(entry.getValue());

            //System.out.println("added next "+entry.getValue());

            _entries.remove(entry.getValue());
        }

        if ((entry == _tail) || (entry == _head))
        {
            _tail = position;
            _tail.setNext(_head);

            if (entry == _head)
                _head = _head.getNext();
        }
        else
        {
            if ((cup == _tail) || (cup == _head))
            {
                _head = _head.getNext().getNext();

                if (cup == _head)
                {
                    _head = _head.getNext();
                }
                else
                    _tail = position;

                _tail.setNext(_head);
            }
            else
                position.setNext(entry.getNext());
        }

        return removed;
    }

    @Override
    public String toString ()
    {
        Iterator<Node> iter = _entries.values().iterator();
        String str = "";

        while (iter.hasNext())
            str += iter.next()+", ";

        return str;
    }

    private HashMap<Integer,Node> _entries;
    private Node _head;
    private Node _tail;
    private Node _current;
}
@@ -2125,17 +2125,16 @@
      if 
-(
 (entry =
@@ -2145,29 +2145,8 @@
 ail)
- %7C%7C (entry == _head))
 %0A   
@@ -2216,16 +2216,49 @@
 _head);%0A
+        %7D %0A        else%0A        %7B
 %0A       
@@ -2274,32 +2274,46 @@
 entry == _head)%0A
+            %7B%0A
                 
@@ -2329,32 +2329,108 @@
 head.getNext();%0A
+                _tail = position;%0A                _tail.setNext(_head);%0A    
         %7D%0A      
@@ -2415,32 +2415,36 @@
 ;%0A            %7D%0A
+    
         else%0A   
@@ -2440,34 +2440,41 @@
    else%0A        
-%7B%0A
+    %7B%0A   
             if (
@@ -2469,20 +2469,20 @@
         
+ 
 if 
-(
 (cup == 
@@ -2491,28 +2491,13 @@
 ail)
- %7C%7C (cup == _head))%0A
+%0A    
     
@@ -2498,32 +2498,36 @@
               %7B%0A
+    
                 
@@ -2553,33 +2553,36 @@
 xt().getNext();%0A
-%0A
+    
                 
@@ -2585,25 +2585,67 @@
     
-if (cup == 
+_tail = position;%0A                    _tail.setNext(
 _head)
+;
 %0A   
@@ -2649,34 +2649,38 @@
                 
-%7B%0A
+%7D%0A    
                 
@@ -2666,32 +2666,38 @@
 %0A               
+ else%0A
          _head =
@@ -2693,50 +2693,54 @@
     
-_head = _head.getNext();%0A                %7D
+       %7B%0A                    if (cup == _head)
 %0A   
@@ -2744,37 +2744,42 @@
                 
-else%0A
+    %7B%0A    
                 
@@ -2787,26 +2787,60 @@
    _
-tail = position;%0A%0A
+head = _head.getNext().getNext().getNext();%0A        
     
@@ -2877,34 +2877,50 @@
 d);%0A            
+       
-%7D%0A
+ %7D %0A       
             else
@@ -2907,37 +2907,46 @@
                 
+ 
 else%0A
+        
                 
@@ -2976,24 +2976,56 @@
 getNext());%0A
+                %7D%0A            %7D%0A
         %7D%0A%0A 

Update CircularLinkedList.java