[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Sort question

Posted on 2003-11-07
2
Medium Priority
?
209 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

656 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