473,569 Members | 2,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Sort a List in Desending Order by the "Value" and Sort the Duplicates by the "

1 New Member
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");

THEN PRINT OUT:

blue >= red ;
&& red >= dodBlue ;
&& dodBlue >= green ;
&& green >= yellow ;
&& yellow >= black ;
&& black >= cyan ;
&& cyan >= orange ;
&& orange >= white ;

*** For your information:
*** SMA is a Simple Moving Average Plotted on a Stock Charting Software Program.
*** (?) is the Period and [0] stands for the Current Bar.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Xml.Serialization;
  8. namespace Indicator
  9. {
  10.     public class SORT_SCRAP : Indicator
  11.     {/// This method is used to configure the indicator and is called once before any bar data is loaded.
  12.         protected override void Initialize()
  13.         {CalculateOnBarClose    = true;
  14.         Overlay    = true;}
  15.         /// Called on each bar update event (incoming tick)
  16.         protected override void OnBarUpdate()
  17.         {if ( CurrentBar < 200 )
  18.         return ;
  19.  
  20.         SortedList sL = new SortedList();
  21.  
  22.         sL.Add(SMA(8)[0], "white");
  23.         sL.Add(SMA(10)[0], "orange");
  24.         sL.Add(SMA(13)[0], "yellow");
  25.         sL.Add(SMA(20)[0], "cyan");
  26.         sL.Add(SMA(30)[0], "black");
  27.         sL.Add(SMA(40)[0], "dodBlue");
  28.         sL.Add(SMA(50)[0], "blue");
  29.         sL.Add(SMA(100)[0], "green");
  30.         sL.Add(SMA(200)[0], "red");
  31.  
  32.         Print("  " + " " + sL.GetByIndex(8) + " " + ">=" + " " + sL.GetByIndex(7));
  33.         Print("&&" + " " + sL.GetByIndex(7) + " " + ">=" + " " + sL.GetByIndex(6));
  34.         Print("&&" + " " + sL.GetByIndex(6) + " " + ">=" + " " + sL.GetByIndex(5));
  35.         Print("&&" + " " + sL.GetByIndex(5) + " " + ">=" + " " + sL.GetByIndex(4));
  36.         Print("&&" + " " + sL.GetByIndex(4) + " " + ">=" + " " + sL.GetByIndex(3));
  37.         Print("&&" + " " + sL.GetByIndex(3) + " " + ">=" + " " + sL.GetByIndex(2));
  38.         Print("&&" + " " + sL.GetByIndex(2) + " " + ">=" + " " + sL.GetByIndex(1));
  39.         Print("&&" + " " + sL.GetByIndex(1) + " " + ">=" + " " + sL.GetByIndex(0));
  40.         }
  41.     }
  42. }
Mar 15 '11 #1
0 1449

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5611
by: Liang | last post by:
Hi, I use "defined $r_libs->{$name}" to check first if a key exists in a hash table. But Perl gives a warning WHENEVER the key exists: "Use of uninitialized value". Would u please help to check the script, and let me know the reason? Thanks in advance. Liang
3
1755
by: Chris Tilley - HPC:Factor | last post by:
Hi, I'm utterly confounded by this one. There must be some sort of rule that I don't know of. I'd consider myself a Newbie+1, so be gentle. I have a database connection (working A-Ok) and a Query String value from a form (passed using GET & working Ok). The server is IIS5. What I'm trying to do is get a simple IF statement to work...
7
17672
by: Diego Barros | last post by:
Hello, I was wondering if it was posibble to sort a map using the values and not the keys. Sorting on the keys (if they were strings, for example) is currently possible. What about, for example, if I have a map with string keys and object values, can I have custom sorting of the items in the map based on member variables of said object? ...
3
2112
by: Phil | last post by:
Hi everybody, I am a XSLT beginner and the following problem really makes me crazy ! I have a main "contacts.xml" document which contains references to several contact data XML files. My aim is to process the contacts in a single-pass XSLT process. That is why the "document()" function is what I need. I call the "document()" XPath...
7
9134
by: Paul Serby | last post by:
Why does '*select count(id) from "tblContacts"'* do a sequential scan when the field '*id*' is indexed using a btree? MySql simply looks at the index which is keeping a handy record of the number of rows. Can anybody explain how and why postgres does this query like it does? Many thanks
3
2960
by: Bob Dankert | last post by:
Is there any way to maintain the sort order of a sort on a 2D array? For example: I have the array: 1,a 2,a 3,f 4,a 5,s 6,a 7,z 8,b and sort it by the second column, and I get: 4,a 6,a 1,a 2,a 8,b 3,f 5,s 7,z
59
4555
by: Pierre Quentel | last post by:
Hi all, In some program I was testing if a variable was a boolean, with this test : if v in My script didn't work in some cases and I eventually found that for v = 0 the test returned True So I changed my test for the obvious "if type(v) is bool", but I still find it confusing that "0 in " returns True
2
2866
by: jobooker | last post by:
I'm having issues sorting. The short description is, how do I set the select attribute of xsl:sort to be the value of an xsl:variable? The longer description follows: What I want to do is to be able to make a data table sortable by different headers. Right now, I've got javascript that lets you click on a column header, and then it changes...
4
1626
by: Abandoned | last post by:
Hi.. I have a dictionary like these: a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} ...... 100.000 element I want to sort this by value and i want to first 100 element.. Result must be: ( first 100 element) I done this using FOR and ITERATOR but it tooks 1 second and this is very big time to my project.
3
3683
by: fastestindian | last post by:
Hi, I am working on the project where i show a list of Log Records. my list is as follows. Original list Id Time Event Details 1 1 Error1 xyz 2 1 Error3 xyz 3 1 Error2 xyz
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.