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

Advertisement

April 18, 2007. Uncategorized.

Leave a Comment

Be the first to comment!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback URI

Follow

Get every new post delivered to your Inbox.