Unique Sorting ({ 1, 1, 5, 5, 5, 9, 3, 3, 3, 9, 9, 9,2 })
Steps for unique sorting:
1. Create console application .
2. Copy following method in ‘Main’ method:
int[] DataArray = { 1, 1, 5, 5, 5, 9, 3, 3, 3, 9, 9, 9,2 };
int[] SortedUniqueData = MakeUnique(DataArray);for (int i = 0; i < SortedUniqueData.Length ; i++){
Console.WriteLine(“Sorted value : {0}”, SortedUniqueData[i]);}
Console.ReadLine();
3. Copy following method to outside ‘Main’ method , but within the same class:
static T[] MakeUnique<T>(T[] values){
System.Collections.Generic.Dictionary<T, bool> dict;dict = new System.Collections.Generic.Dictionary<T, bool>();
foreach (T value in values)if (!dict.ContainsKey(value)) dict.Add(value, false);
List<T> newDict = new List<T>(dict.Keys);newDict.Sort();
return newDict.ToArray();}
4. Now run the application, u will get unique sorting result.
cheearo man
Leave a Comment
Be the first to comment!