In my arrayList, i have number which are shown below:
1 2
1
2
2 1
2
1
2 3
2
3
1 2 3
1 2
3
3 1
3
1
1 3 2
1 3
2
2 3 1
2 3
1
now i want to sort some number.
For example: (i) 2 3 in ArrayList, i wan sort it to 1 2.
(ii) 2 3 1 in ArrayList, i wan sort it in 1 2 3.
may i know how to sort the number?
hope anyone can help me..
Loading
y sPosted Apr 6, 2011, 5:49 PM
Now i meet another problem.
that is i need to use the value from sortlist8 to do calculation .
My total transaction is 5.
for example-> 1 2:3
therefore, i need to use the value divide by total transaction.
the formula is : sortlist8.Value/ total transaction
here is my coding.
Dictionary
string sigh = "";
foreach (string ry in ang)
{
if (sortList2.ContainsKey(ry))
{
if (!sortList8.ContainsKey(ry))
{sortList8.Add(ry, sortList[ry]);
}
sigh += String.Format("{0}:{1}\r\n", ry, sortList8[ry]) ;
}
}
richTextBox12.Clear();
richTextBox12.AppendText(sigh);
string b = txtTotalItems.Text;
double e = Double.Parse(b);
double a;
richTextBox9.Clear();
foreach (double wee in sortList8.Values)
{
a = (wee / e);
richTextBox9.AppendText(a.ToString() + "\n");
}
now my problem is i just can show some only, there are:
0.6
0.6
0.6
0.4
Actually, my expected output is :
0.6
0.6
0.6
0.6
0.4
0.6
0.6
0.4
May i know any error with my coding?
VulpesPosted Apr 6, 2011, 4:33 PM
Here's your data and code modelled as a console app:
The output is as follows (exactly what you want):
1 2:3
1 3:3
1 2:3
2 3:3
1 2 3:2
1 3:3
2 3:3
1 2 3:2
y sPosted Apr 6, 2011, 12:59 PM
my arrayList are shown below:
1 2
1 3
1 2
2 3
1 2 3
1 3
2 3
1 2 3
my another sortedeList are shown below:
(1): 4
(2): 4
(1 2): 3
(3): 4
(1 3): 3
(2 3): 3
(1 2 3): 2
Now my problem is i want to compare arrayList with sortedList . if the key are same, then will show value.
my expected output is :
1 2:3
1 3:3
1 2:3
2 3:3
1 2 3:2
1 3:3
2 3:3
1 2 3:2
my code are below:
Dictionary
string sigh = "";
foreach (string ry in ang)
{
if (sortList2.ContainsKey(ry))
{
if (!sortList8.ContainsKey(ry))
{
sortList8.Add(ry, sortList[ry]);
sigh += String.Format("{0}:{1}\r\n", ry, sortList8[ry]);
}
}
}
richTextBox12.Clear();
richTextBox12.AppendText(sigh);
hope someone can help me..thx..
Suthish NairPosted Apr 4, 2011, 11:01 AM
VulpesPosted Apr 3, 2011, 7:31 PM
To maintain the correct order, replace sortList2 with an ordinary List:
List
string text = "";
foreach (string key in arryKey)
{
if (sortList.ContainsKey(key))
{
string temp = String.Format("{0}:{1}", key, sortList[key])
list2.Add(temp);
text += String.Format("{0}\r\n", temp);
}
}
richTextBox5.Clear();
richTextBox5.AppendText(text);
y sPosted Apr 3, 2011, 2:45 PM
now if i take the arrayList that already sort to compare with my another sortedLIst.
my sortedLIst is show below:
(1): 4
(2): 4
(1 2): 3
(3): 4
(1 3): 3
(2 3): 3
(1 2 3): 2
i wan the output is like this:
1 2:3
1:4
2:4
1 2:3
2:4
1:4
2 3:3
2:4
3:4
1 2 3:2
1 2:3
3:4
1 3:3
may i know how to correct the code below?
richTextBox6.Clear();
ArrayList arryKey = new ArrayList(richTextBox4.Lines);
for (int i = 0; i < arryKey.Count; i++)
{
string temp = (string)arryKey[i];
string[] numbers = temp.Trim().Split(' ');
Array.Sort(numbers);
arryKey[i] = String.Join(" ", numbers);
richTextBox6.AppendText(arryKey[i].ToString()+"\n");
}
SortedList
string text = "";
foreach (string key in arryKey)
{
if (sortList.ContainsKey(key))
{
if (!sortList2.ContainsKey(key))
{
sortList2.Add(key, sortList[key]);
text += String.Format("{0}:{1}\r\n", key, sortList2[key]);
}
}
}
richTextBox5.Clear();
richTextBox5.AppendText(text);
VulpesPosted Apr 3, 2011, 1:52 PM