I have looked All over the Internet to try and find an example of How to fix the following.
How to Sort a List in Desending Order by the "Value" and Sort the Duplicates by the "Key" ?
Then Print out the Results in the format below.
I have enclosed my code and it works, but the problem happens when there are duplicate values, which occurs when you use SortedList(). I would GREATLY APPRECIATE it if someone could PLEASE Modify this Code or Show me EXACTLY how to do this another way, that is just as quick and efficent.
THANK YOU VERY MUCH in Advance.
BEFORE SORT:
VALUE's, KEY's
sL.Add(1269.63,"white");
sL.Add(1270.36,"orange");
sL.Add(1272.06,"yellow");
sL.Add(1271.50,"cyan");
sL.Add(1272.06,"black");
sL.Add(1274.12,"dodBlue");
sL.Add(1276.02,"blue");
sL.Add(1273.21,"green");
sL.Add(1275.52,"red");
AFTER SORT:
VALUE's, KEY's
sL.Add(1276.02,"blue");
sL.Add(1275.52,"red");
sL.Add(1274.12,"dodBlue");
sL.Add(1273.21,"green");
sL.Add(1272.06,"black");
sL.Add(1272.06,"yellow");
sL.Add(1271.50,"cyan");
sL.Add(1270.36,"orange");
sL.Add(1269.63,"white");
CODE:
SortedList sL = new SortedList();
sL.Add(SMA(8)[0], "white");
sL.Add(SMA(10)[0], "orange");
sL.Add(SMA(13)[0], "yellow");
sL.Add(SMA(20)[0], "cyan");
sL.Add(SMA(30)[0], "black");
sL.Add(SMA(40)[0], "dodBlue");
sL.Add(SMA(50)[0], "blue");
sL.Add(SMA(100)[0], "green");
sL.Add(SMA(200)[0], "red");
Print(" " + " " + sL.GetByIndex(8) + " " + ">=" + " " + sL.GetByIndex(7));
Print("&&" + " " + sL.GetByIndex(7) + " " + ">=" + " " + sL.GetByIndex(6));
Print("&&" + " " + sL.GetByIndex(6) + " " + ">=" + " " + sL.GetByIndex(5));
Print("&&" + " " + sL.GetByIndex(5) + " " + ">=" + " " + sL.GetByIndex(4));
Print("&&" + " " + sL.GetByIndex(4) + " " + ">=" + " " + sL.GetByIndex(3));
Print("&&" + " " + sL.GetByIndex(3) + " " + ">=" + " " + sL.GetByIndex(2));
Print("&&" + " " + sL.GetByIndex(2) + " " + ">=" + " " + sL.GetByIndex(1));
Print("&&" + " " + sL.GetByIndex(1) + " " + ">=" + " " + sL.GetByIndex(0));
PRINT OUT RESULTS:
blue >= red ;
&& red >= dodBlue ;
&& dodBlue >= green ;
&& green >= yellow ;
&& yellow >= black ;
&& black >= cyan ;
&& cyan >= orange ;
&& orange >= white ;
VulpesPosted Mar 17, 2011, 5:36 AM
Joe CaggianoPosted Mar 17, 2011, 3:11 PM
Truely, THANK YOU for all the Help and your Time !!!!!!
Joe
Joe CaggianoPosted Mar 17, 2011, 2:47 AM
THANK YOU for your through explanation, It realy helped me to understand what's going on.
You were wright it was my error that caused the "&&" to Print.
I would like to ask you one more question.
I created an alternative way to Print out the Results.
I was wondering if Performance (Time) wise, structural wise, etc... is one method to Print out the Results more efficient than the other ???
The only benefit I can see using the for(i = 0 to i = x) --> Print method, is that it would be easier to create a Print out, if your "var list" was very large (less code).
Print( list[0].Value + " >= " + list[1].Value + ";");
Print("&& " + list[1].Value + " >= " + list[2].Value + ";");
Print("&& " + list[2].Value + " >= " + list[3].Value + ";");
Print("&& " + list[3].Value + " >= " + list[4].Value + ";");
Print("&& " + list[4].Value + " >= " + list[5].Value + ";");
Print("&& " + list[5].Value + " >= " + list[6].Value + ";");
Print("&& " + list[6].Value + " >= " + list[7].Value + ";");
Print("&& " + list[7].Value + " >= " + list[8].Value + ";");
Suthish NairPosted Mar 16, 2011, 3:28 PM
VulpesPosted Mar 16, 2011, 1:01 PM
Joe CaggianoPosted Mar 16, 2011, 12:36 PM
THANKs AGAIN!!!
This also Works!!!
There's Only one Problem the First Line also Prints Out with the "&&".
&& blue >= red ; <------- Should Be: blue >= red; ???
&& red >= dodBlue ;
&& dodBlue >= green ;
&& green >= yellow ;
&& yellow >= black ;
&& black >= cyan ;
&& cyan >= orange ;
&& orange >= white ;
Could you PLEASE elaborate on what "\r\n\r\n" means and also "{0}{1} >= {2};{3}" what is it saying and doing ???
THANK You Once Again for you Time and Support !!!
VulpesPosted Mar 16, 2011, 7:52 AM
However, assuming it recognizes new lines (normally "\r\n" in Windows), this should work:
Joe CaggianoPosted Mar 15, 2011, 8:51 PM
Thanks for your Help, it Sorts the Duplicate Items like a Charm.
I still have a problem with Printing out the Sort Results.
My software does not recognize the Console.WriteLine("{0:F2} : {1}", pair.Key, pair.Value).
It uses the Print() command to Print to the OutPut Window of the software.
Could you Please tell me how I can access the Values in the sorted List so I can print them out accordingly?
Print(pair.Value(0) + " " + ">=" + " " + pair.Value(1) + ";") <------------------- ???
Print("&&" + " " + pair.Value(1) + " " + ">=" + " " + pair.Value(2) + ";") <------- ???
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
Print("&&" + " " + pair.Value(6) + " " + ">=" + " " + pair.Value(7) + ";") <-------- ???
Print("&&" + " " + pair.Value(7) + " " + ">=" + " " + pair.Value(8) + ";") <-------- ???
So the Print out looks Like the Following:
blue >= red ;
&& red >= dodBlue ;
&& dodBlue >= green ;
&& green >= yellow ;
&& yellow >= black ;
&& black >= cyan ;
&& cyan >= orange ;
&& orange >= white ;
THANK YOU VERY MUCH IN ADVANCE.
VulpesPosted Mar 15, 2011, 6:32 AM
Console.ReadKey();