注册 登录
编程论坛 C# 论坛

有关C#数据结构链表排序问题

冷锋2048 发布于 2016-06-01 22:21, 1914 次点击
//链表的排序
        public void paixu(ref LinkedList a)//a为链表
        {

            Node tempNode = a.head;
            for (int i = 0; i < count + 1; i++)
            {
                int x = 1;
                x = x + i;
                for (int j = 0; j < count + 1; j++)
                {
                        if ((int)a.head.item > (int)a.head.next.item)
                        {
                            a.head.next.next = a.head .next;
                             a.head.next =  a.head;
                        }
                        else
                        {
                            continue;
                        }                 
                        if ((int)tempNode.item > (int)tempNode.next.item & tempNode.next.next != null)
                        {
                            Node preNode = GetByIndex(x - 1);
                            tempNode.next = preNode.next;
                            tempNode = tempNode.next;
                            tempNode.next.next = tempNode.next;
                            x++;
                        }
                        else
                        {
                            x++;
                        }
                        if ((int)tempNode.item > (int)tempNode.next.item & tempNode.next.next == null)
                        {
                            Node preNode = GetByIndex(x - 1);
                            tempNode.next = preNode.next;
                            tempNode = tempNode.next;
                        }                  
                    tempNode = tempNode.next;
                }
            }
0 回复
1