Board index » cppbuilder » Unsort a StringList...How ?

Unsort a StringList...How ?


2003-07-23 05:24:00 AM
cppbuilder80
hi dear builders,
I'm using the following to sort a StringList:
******************************************/
void __fastcall TForm1::SortThem1Click(TObject *Sender)
{
TStringList *sList = new TStringList;
sList->Sorted = true;
sList->Duplicates = dupAccept;
sList->AddStrings(Memo1->Lines);
Memo1->Lines->Assign(sList);
delete sList;
}
/******************************************/
Now my question: How can I "Unsort" a StringList...?
Can I use something like:
Randomize(Memo1->Lines->Count[x]);
I just need something like that:
B
C
A
D
Not this:
A
B
C
D
Can someone help me with this ??
Oren
 
 

Re:Unsort a StringList...How ?

Try setting up a second TStringList.
Then (this is psuedocode)
int ANumber
Create TStringListA
Create TStringListB
Put Data into TSTringlist A
Sort TStringList A
while TStringListA.Count>0 do
begin
ANumber = RandomNumber(seed = TStringList.Count-1)
TStringListB.Add(TStringListA.String[ANumber]
TStringListA.Delete(ANumber)
end
// et voila. One randomised TStringList
TStringListA = TStringListB
// et voila - list now transferred.
Rhys Sage.
www.sageworld.freeserve.co.uk for
code snippets and software downloads.
 

Re:Unsort a StringList...How ?

Hi Rhys, thanks for the "very quick" reply..
I see you like Delphi :-)
Quote
begin
ANumber = RandomNumber(seed = TStringList.Count-1)
TStringListB.Add(TStringListA.String[ANumber]
TStringListA.Delete(ANumber)
end
I'll try to translate it to C++ code :-)
Oren
 

{smallsort}

Re:Unsort a StringList...How ?

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
Quote
Now my question: How can I "Unsort" a StringList...?
Can't be done automatically. You'll just have to store the strings to
another unsorted list, adding them in random order. Or else just use the
Exchange() method to swpa some of the indexes around within the same list.
Gambit
 

Re:Unsort a StringList...How ?

It's an easy answer. It's not pure Delphi. I said it was psuedocode. At
11:16PM, I really don't feel like thinking too hard. Don't forget to
Randomize your random number generator or the random numbers will come out
in a predictable sequence.
Yes, I do most of my programming, these days, in Delphi. There are just so
many more code examples availble for Delphi. It also helps that I have
Delphi 7 and Delphi 3 as opposed to just C++ 3.
Having said that, I seem to write all my dlls in D3 and my GUI stuff in D7.
Rhys Sage.
www.sageworld.freeserve.co.uk for
code snippets and software downloads.