bubble sort

I'm trying to sort people inside a listbox based on the number of their bookings

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

 int iEnd = ListBox1->Items->Count - 1;
 AnsiString str1,str2,temp;
 while (x)
	{
		x = false;
		for (int i = 0; i <iEnd ; i++)
		 {
			str1 = ListBox1->Items->Strings[i];
			str2 = ListBox1->Items->Strings[i+1];	
			str1 = str1.SubString(str1.AnsiPos("#")+1,100);
			str2 = str2.SubString(str2.AnsiPos("#")+1,100);
			if (str1.ToInt() < str2.ToInt()) 
			 {
			   temp = ListBox1->Items->Strings[i+1];
			   ListBox1->Items->Strings[i+1] = ListBox1->Items->Strings[i];
				ListBox1->Items->Strings[i] = temp;
			 }
		 }
		 iEnd--;
	} 




But it only sorts the first 2 people only
Original list Pretorius Correlie#1
Lemmer Summayah#16
Erasmus Henriette Gertrud#1
Januarie Lynn Melissa#26
Swartz Tamaran#20
Moore Dane#14
Schlumf Barry#17
Greyling Kylie#22
Jaftha Eden#17
Majali Tamsyn#16
Appolis Darion#18
Draai Oreal Isabel#17
Lombard Shelby#21
Higgins Lee-Ann#19
Mayola Ndiphiwe#22
Layman Lucille#13
Navsaria Sachen#28
Govender Trevlin#20
Smith David#14
Du Buson Gabriela#31
Links Shannon#22
Pow Chong Curt#21
Smith Kyle#19
Thomas Carla#16
Losi Lelethu Siyasanga#23
Fortune Karen#20
Sithonga Siphiwo#21
Mgoqo Neliswa#22
the sorted list
Lemmer Summayah#16
Pretorius Correlie#1
Januarie Lynn Melissa#26
Swartz Tamaran#20
Moore Dane#14
Schlumf Barry#17
Greyling Kylie#22
Jaftha Eden#17
Majali Tamsyn#16
Appolis Darion#18
Draai Oreal Isabel#17
Lombard Shelby#21
Higgins Lee-Ann#19
Mayola Ndiphiwe#22
Layman Lucille#13
Navsaria Sachen#28
Govender Trevlin#20
Smith David#14
Du Buson Gabriela#31
Links Shannon#22
Pow Chong Curt#21
Smith Kyle#19
Thomas Carla#16
Losi Lelethu Siyasanga#23
Fortune Karen#20
Sithonga Siphiwo#21
Mgoqo Neliswa#22
Suka Zandile#14
Scotson Jason#19
Frost Jurisa#18
Terblanche Damian#22
Gin Justin#26
Jesson Maxine#16
Pillay Ariana#23
Stuurman Anna#20
Goosen Avela#16
Speelman Yolisa#24
Dealtry Clair#19
Hendrick Lauren#25
Ally Shae#16
Are you using C++ Builder??
Sort your data using std::sort first, then add it to the listbox.
Yes but the emabarcadero c++ builder 2010.....using std::sort it gives me some unresolved data link error
OK, if you're using Emabarcadero c++ builder, there might be another way to solve your problem.

I've never use C++ Builder, but I have used Delphi and Lazarus, and the classes do look very similar to me.

If Builder provides you with the TStringList class and it has a CustomSort method, and TListBox's Items is a TStrings, then you might be able to port this Delphi code to C++

Custom sort a TCheckListBox
http://delphicikk.atw.hu/listaz.php?id=694&oldal=11
Thanx :-)
Did the "Delphi" style approach work???
Yes it did :-)
Topic archived. No new replies allowed.