2013-07-01 13 views
-3

我需要創建一個排序方法,將名字排序根據字母順序排列。我根本不能使用任何種類的數組。 任何幫助,將不勝感激。在不使用數組的情況下在鏈接列表類中創建排序方法。 C#

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--; 
     } 
    } 
} 
+0

我想你忘了問一個問題。你怎麼了? –

+0

如何添加一個排序方法到當前鏈表類?使用數組的排序方法背後的邏輯是什麼? –

回答

1

你可能想使用Merge Sort這一點,它不需要隨機存取/陣列。下面是一個example(它在C,但應該是很容易轉移)。

相關問題