Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to sort array of structures

New Here ,
Oct 02, 2009 Oct 02, 2009

Hi !

I populated an array of structures:

ind is increased in a query loop:

<CFSET TD[ind] = StructNew()>

<cfset TD[ind].V1 = "#qryTermst.v1#">

<cfset TD[ind].V2 = "#qryTermst.v2#">

<cfset TD[ind].V3 = "#qryTermst.v3#">

<cfset TD[ind].D = "#DateFormat(qryTermst.date, 'M/D/YYYY')#">

<cfset TD[ind].V5 = "#qryTermst.v5#">

After the array is populated- later - I need to display it in descending order of D (dates) and in ascending order of V1.

I tried to use the StructSort function, but did not get results.

Any help will be appreciated !

Regards !

1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2009 Oct 02, 2009

Are you sure you need an array of structures?  If every structure has the same format, you might be able to achieve your final goal with a query object instead.  They are much easier to sort.

Once you figure out how to sort, you will find that you are probably not getting the desired results.  You are storing your date as a string instead of a date object, so it will sort as a string.  Now look at the format you chose.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 02, 2009 Oct 02, 2009

Sorry, but I next prepare reports based on the elements of this array (of structures).

So it is easier for me to store data (which I actually read from a query object) in this array...

I actually tried to sort an array- prepeared an array of keys- then (in cfloop) tried to read "sorted" elements (structures) - got error, so far.

There must be an easy way to sort at least some keys- like I tried.

Any ideas ?

Samples ?

Thanks !

Gary.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2009 Oct 03, 2009
LATEST

I gotta agree with Dan here.  An array of struts isn't such a good data structure for you to land yourself with here.  But I suppose it can't be helped.

Sorry, but I next prepare reports based on the elements of this array (of structures).

Do you mean the code for the reports already exists and expects an array of structs?  And you can't change that?

Anyway, if you're stuck where you are, you should perhaps look @ the quickSort() function on cflib.org: http://www.cflib.org/udf/QuickSort

I've never used it, but it sounds like it'll do what you want.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources