Java 如何对该圆圈列表进行排序?

Java 如何对该圆圈列表进行排序?,java,sorting,Java,Sorting,我试图找出如何创建一个排序的圆形列表类。我有一个未排序的类,但我似乎在排序列表时遇到了问题。我已经试着在其他程序中使用的排序列表类的帮助下解决这个问题。我认为我需要使用compareTo方法,但我似乎不知道该怎么做 public class CRefUnsortedList<T extends Comparable<T>> implements ListInterface<T> { protected int numElements; prot

我试图找出如何创建一个排序的圆形列表类。我有一个未排序的类,但我似乎在排序列表时遇到了问题。我已经试着在其他程序中使用的排序列表类的帮助下解决这个问题。我认为我需要使用compareTo方法,但我似乎不知道该怎么做

public class CRefUnsortedList<T extends Comparable<T>> implements ListInterface<T>
{
    protected int numElements;
    protected LLNode<T> currentPos;
    protected boolean found;
    protected LLNode<T> location;
    protected LLNode<T> previous;

    protected LLNode<T> list;

    public CRefUnsortedList()
    {
        numElements = 0;
        list = null;
        currentPos = null;
    }

    public void reset()
    {
        if (list != null)
        {
            currentPos = list.getLink();
        }
    }

    public T getNext()
    {
        T next = currentPos.getInfo();
        currentPos = currentPos.getLink();
        return next;
    }

    public String toString()
    {
        String listString = "List:\n";
        if(list != null)
        {
            LLNode<T> prevNode = list;
            do
            {
                listString = listString + " " + prevNode.getLink().getInfo() + "\n";
                prevNode = prevNode.getLink();
            }while(prevNode != list);
        }
        return listString;
    }

    protected void find(T target)
    {
        location = list;
        found = false;

        if(list != null)
        {
            do
            {
                previous = location;
                location = location.getLink();

                if(location.getInfo().equals(target))
                {
                    found = true;
                }
            }while((location != list) && !found);
        }
    }

    public boolean remove (T element)
    {
        find(element);
        if(found)
        {
            if(list == list.getLink())
            {
                list = null;
            }
            else
            {
                if (previous.getLink() == list)
                {
                    list = previous;
                }
                else
                {
                    previous.setLink(location.getLink());
                }
                numElements--;
            }
        }
        return found;
    }

    public T get(T element)
    {
        find(element);
        if (found)
        {
            return location.getInfo();
        }
        else
        {
            return null;
        }
    }

    public void add(T element)
    {
        LLNode<T> newNode = new LLNode<T>(element);
        if(list == null)
        {
            list = newNode;
            newNode.setLink(list);
        }
        else
        {
            newNode.setLink(list.getLink());
            list.setLink(newNode);
            list = newNode;
        }
        numElements++;
    }

    public int size()
    {
        return numElements;
    }

    public boolean contains(T element)
    {
        find(element);
        return found;
    }
}

我想这取决于Circle班。排序标准是什么?这似乎需要做很多工作。为什么不扩展ArrayList并使用标准集合排序呢。然后你所要做的就是重写get并使用模数学使检索元素循环。它只需要对对象进行排序,比如按字母顺序对字符串进行排序。我必须使用ciruclar链表,因为这就是我现在正在研究的