-3

我需要创建一个排序方法,该方法将根据名称的字母顺序进行排序。我根本不能使用任何类型的数组。任何帮助,将不胜感激。

SortByCustomerName():此方法将链表按客户名称升序排序。

class LinkedList
{
    private Node head;  // first node in the linked list
    private int count;

    public int Count
    {
        get { return count; }
        set { count = value; }
    }

    public Node Head
    {
        get { return head; }
    }
    public LinkedList()
    {
        head = null;    // creates an empty linked list
        count = 0;
    }

    public void AddFront(int n)
    {
        Node newNode = new Node(n);
        newNode.Link = head;
        head = newNode;
        count++;

    }
    public void DeleteFront()
    {
        if (count > 0)
        {
            Node temp = head;
            head = temp.Link;
            temp = null;
            count--;
        }
    }
}
4

1 回答 1

1

您可能希望为此使用合并排序,它不需要随机访问/数组。这是一个例子(它在 C 中,但应该很容易转移)。

于 2013-07-01T02:46:00.173 回答