?
Solved

Sort question

Posted on 2003-11-07
2
Medium Priority
?
208 Views
Last Modified: 2010-04-05
I have up to 4000 items to sort.  These items need to be sorted on 2 fields - first on a numeric field and then on a string field.  For example:

1,widget; 3,zebra; 1,apple should be sorted as 1,apple; 1,widget; 3,zebra.

I don't have a particular data structure in mind yet.  Could anyone tell me what will be the most efficient way and structure for this kind of sort.  There are a number of options available but I would like to minimize memory usage and maximize speed.  

Thanks for any guidance.
alexia
0
Comment
Question by:alexiat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
monir earned 2000 total points
ID: 9703388
The fastest sort algorithm is Quick Sort, in Delphi we have TList, so declare a class for your Item,

TItem = clase

  Int: integer;
  str: string;

 constructor create( i: int; s: string);
end;

 then store the items in TList

MyList: TList;

for i:=1 to 4000
  MyList.Add ( TItem.Create (v1, V2));

finally use sort method inside TList.

MyList.Sort (@sortItem);

function sortItem  ( Item1,Item2:Pointer) :Integer;
begin
  result:=TItem (Item1).int - TItem (Item2).Int);
  if  result=0 then // Same Value
     result:=CompareText(TItem (Item1).Str,TItem (Item2).str) ;
end;


If you need more description I will send you a tiny sample of code.

Monir
0
 

Author Comment

by:alexiat
ID: 9703608
Thanks.  Just wasn't sure which sort and data structure would be the most efficient.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question