示例#1
0
        const int NUM_OF_NUM = 3;   //实际关键字个数
        static void Main(string[] args)
        {
            string[] y = new string[] { "369", "367", "167", "239", "237", "138", "230", "139" };

            SLList list = new SLList();

            //初始化list
            list.recnum = y.Length;
            list.keynum = NUM_OF_NUM;
            list.r      = new List <SLCell>();  //实例化该List对象,C#不允许就地初始化,Java可以,C++17也可以
            for (int i = 0; i < list.recnum; i++)
            {
                SLCell slCell = new SLCell();
                slCell.keys = y[i];
                list.r.Add(slCell);
            }

            Console.Write("Before Sort : ");    //排序前
            for (int i = 0; i < y.Length; i++)
            {
                Console.Write(y[i] + "   ");
            }
            Console.WriteLine();

            RadixSort(list);

            Console.Write("After Sort  : ");    //排序后
            RadixPrint(list);

            Console.ReadLine();
        }
示例#2
0
        static void RadixPrint(SLList list)
        {
            int p = head;

            for (int i = 0; i < list.recnum; i++)
            {
                Console.Write(list.r[p].keys + "   ");
                p = list.r[p].next;
            }
            Console.WriteLine();
        }
示例#3
0
 static void RadixSort(SLList list)
 {
     for (int i = 0; i < list.recnum; i++)
     {
         list.r[i].next = i + 1;
     }
     list.r[list.recnum - 1].next = -1;
     int[] f = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
     int[] r = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
     for (int i = 0; i < list.keynum; i++)
     {
         Distribute(list.r, i, f, r, head);
         head = Collect(list.r, f, r, head);
     }
 }