0

Hey ...i want to use the arraylist to sort the item based on the item frequency ..how i do that..?

for example,
item:frequency
1: 7
2: 8
3: 4
4: 7
5: 1

my expected output is
item: frequency
2: 8
1: 7
4: 7
3: 4
5: 1
here is my coding

IDictionaryEnumerator enumerator2 = sItem.GetEnumerator();
                        ArrayList myArrayList = new ArrayList();
                        while(enumerator2.MoveNext())
                        {
                            show += enumerator2.Key.ToString() + ":" + enumerator2.Value.ToString()+"\n";     
                            myArrayList.Add(show);                
                        }
                        //MessageBox.Show(show.ToString());
                       
                         myArrayList.Sort();
                         myArrayList.Reverse();
                         foreach(String rec in myArrayList)
{
MessageBox.Show(rec);
}

Hope someone can help me..thanks ya..

Edited by Kath_Fish: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Kath_Fish
0
while (enumerator.MoveNext())
                        {
                            //showFile1.Items.Add(enumerator.Key.ToString() + ":" + enumerator.Value.ToString() + "\r\n");
                            //showFile1.Items.Add( enumerator.Key.ToString());

                            KeyItems1 = (enumerator.Key.ToString()).Split(' ');
                            KeyItems2 = new String[KeyItems1.Length];
                            int i;
                            for (i = 0; i < KeyItems1.Length; i++)
                            {
                                KeyItems2[i] = KeyItems1[i];
                                // MessageBox.Show(Keyitems2[i]);
                                // show += Keyitems2[i] + "\n";
                                // number = Convert.ToInt32(Keyitems2[i]);

                            }

                            foreach (String y in KeyItems2)
                            {
                                if (!(sItem.ContainsKey(y)))
                                {
                                    sItem.Add(y, 1);
                                }
                                else
                                {
                                    int count = (int)sItem[y];
                                    sItem[y] = count + 1;
                                }
                            }

                        } // MessageBox.Show(show.ToString());

                       //count single items frequency
                        IDictionaryEnumerator enumerator2 = sItem.GetEnumerator();
                        ArrayList myArrayList = new ArrayList();
                        while(enumerator2.MoveNext())
                        {
                            showFile1.Items.Add(enumerator2.Key +":"+ enumerator2.Value);
                            myArrayList.Add(showFile1.Items);             
                        }
                       // MessageBox.Show(show.ToString());
                        myArrayList.Sort();
                        myArrayList.Reverse();
                       
                        foreach(string rec in myArrayList)
                        {
                            MessageBox.Show(rec.ToString());
                        }

this is the code i did ... but got errors....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.