Sorting a linked list

前端 未结 8 735
-上瘾入骨i
-上瘾入骨i 2020-11-29 09:26

I have written a basic linked list class in C#. It has a Node object, which (obviously) represents every node in the list.

The code does not use IEnumerable, however

相关标签:
8条回答
  • 2020-11-29 10:25

    Of course you can implement a sorting function using a plain linked list. Merge sort might be a suitable algorithm to try, it's fairly simple.

    0 讨论(0)
  • 2020-11-29 10:27
    for(int i=0; i<counter;i++)
    {
      while(current.next!=null)
      {
        if(current.elemen>current.next.element)
        {
          Swap(current.elment,current.next.element);
        }
        current=current.next;
      }
    }
    

    increment counter when you add or insert elements to your linked lists

    0 讨论(0)
提交回复
热议问题