hashtable排序

    按Hashtable中的值得大小就行排序 .
    原理同上:实际上是按照每一个字符的ASCII的值就行排序的。从左到右比较每个字符的Ascii的值,直到满足两个字符的ASCII的值不同即停止比较。


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections;

  6. namespace HashtableSort
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Hashtable ht = new Hashtable();
  13.             ht.Add("aa", 88);
  14.             ht.Add("bb", 33);
  15.             ht.Add("cc", 33);
  16.             ht.Add("dd", 22);
  17.             ht.Add("ee", 11);
  18.             ht.Add("ff", 99);
  19.             ArrayList list = new ArrayList(ht.Values);

  20.             /* 转换成整数的排序 */
  21.             for (int i = 0; i list.Count; i++)
  22.                 list[i] = Convert.ToInt32(list[i]);

  23.             // Sort为升序排序
  24.             list.Sort();
  25.             // 将顺序反转
  26.             list.Reverse();

  27.             Hashtable tmpHT = new Hashtable();
  28.             foreach (int value in list)
  29.             {
  30.                 IDictionaryEnumerator ide = ht.GetEnumerator();
  31.                 while (ide.MoveNext())
  32.                 {
  33.                     if (Convert.ToInt32(ide.Value) == value && !tmpHT.ContainsKey(ide.Key))
  34.                     {
  35.                         Console.WriteLine(ide.Key + ":"+value);
  36.                         tmpHT.Add(ide.Key, ide.Value);
  37.                     }
  38.                 }
  39.             }
  40.             Console.ReadLine();
  41.         }
  42.     }
  43. }


hashtable排序


参考文献:

http://blog.sina.com.cn/s/blog_5f120d690100odit.html

上一篇:Arraylist中对象属性的排序


下一篇:DataWorks支持PyODPS类型任务