| | |
Sorting a ListBox
Thread Solved
![]() |
•
•
Join Date: May 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi happy people
I've bin trying to sort items in a list box, the problem is obviously: It doesn't work
Please, any modifications to the code below is fully and unconditionally allowed.
I've bin trying to sort items in a list box, the problem is obviously: It doesn't work
Please, any modifications to the code below is fully and unconditionally allowed.
C++ Syntax (Toggle Plain Text)
void __fastcall TForm1::btnSortClick(TObject *Sender) { //sort ascending if (rdAscending->Checked){ bool swopped = true; int iEnd; int arr = lstWords->Count; //ShowMessage(arr); iEnd = arr -1; while (swopped) { swopped = false; for (int c=0; c < iEnd; c++) { AnsiString a = lstWords->Items->Strings[c]; AnsiString b = lstWords->Items->Strings[c+1]; if (a > b) { AnsiString txt = lstWords->Items->Strings[c]; lstWords->Items->Strings[c] = lstWords->Items->Strings[c+1]; lstWords->Items->Strings[c+1] = txt; swopped = true; iEnd--; } } } 'Let us do what we do best!' } //sort descending else if (rdDescending->Checked){ bool swopped = true; int iEnd; int arr = lstWords->Count; iEnd = arr -1; while (swopped) { swopped = false; for (int c=0; c < iEnd; c++) { AnsiString a = lstWords->Items->Strings[c]; AnsiString b = lstWords->Items->Strings[c+1]; if (a < b) { AnsiString txt = lstWords->Items->Strings[c]; lstWords->Items->Strings[c] = lstWords->Items->Strings[c+1]; lstWords->Items->Strings[c+1] = txt; swopped = true; iEnd--; } } } } else ShowMessage( "Select either [Ascending] or [Descending]! \nPlease Try Again!"); }
![]() |
Similar Threads
- Starting Python (Python)
- Sorting has me out of sorts. (Visual Basic 4 / 5 / 6)
- Sorting in date order (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: creating a infinate loop
- Next Thread: Compiler for Xda Exec (Windows Mob v5)
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes classified code coding compatible compile console conversion count date delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file filewrite forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper homeworksolutions iamthwee icon if...else ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node object output play pointer problem program programming project python random read recursion reference rpg string strings struct symbol temperature template test text text-file toolkit tree url values variable vector video win32 windows winsock wordfrequency wxwidgets





