Click here to Skip to main content
15,895,656 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: CPU id Pin
Mazdak2-Jan-04 3:10
Mazdak2-Jan-04 3:10 
GeneralSorting problems Pin
Rafael Fernández López2-Jan-04 2:16
Rafael Fernández López2-Jan-04 2:16 
GeneralRe: Sorting problems Pin
utkarsharma2-Jan-04 2:42
utkarsharma2-Jan-04 2:42 
GeneralRe: Sorting problems Pin
Rafael Fernández López2-Jan-04 2:48
Rafael Fernández López2-Jan-04 2:48 
GeneralRe: Sorting problems Pin
utkarsharma2-Jan-04 3:06
utkarsharma2-Jan-04 3:06 
GeneralRe: Sorting problems Pin
Rafael Fernández López2-Jan-04 3:09
Rafael Fernández López2-Jan-04 3:09 
GeneralRe: Sorting problems Pin
utkarsharma2-Jan-04 3:34
utkarsharma2-Jan-04 3:34 
GeneralRe: Sorting problems Pin
utkarsharma2-Jan-04 3:34
utkarsharma2-Jan-04 3:34 
hi honey..
You can use the sample code sort a CStringArray object.
The main() function constructs a CStringArray object,
adds elements to it, prints out the elements,
calls the sort() member function to sort it, and then prints the sorted elements.
The sort() function uses the Bubble Sort algorithm to sort the array and calls the CompareAndSwap()
function to compare each string and swap them if necessary.

//Sample Code
/*
* Compile options needed: /MT
*/



class CSortStringArray : public CStringArray {
public:
void Sort();
private:
BOOL CompareAndSwap(int pos);
};
void CSortStringArray::Sort()
{
BOOL bNotDone = TRUE;

while (bNotDone)
{
bNotDone = FALSE;
for(int pos = 0;pos < GetUpperBound();pos++)
bNotDone |= CompareAndSwap(pos);
}
}
BOOL CSortStringArray::CompareAndSwap(int pos)
{
CString temp;
int posFirst = pos;
int posNext = pos + 1;

if (GetAt(posFirst).CompareNoCase(GetAt(posNext)) > 0)
{
temp = GetAt(posFirst);
SetAt(posFirst, GetAt(posNext));
SetAt(posNext, temp);
return TRUE;

}
return FALSE;
}
void main()
{
CSortStringArray sortArray;

sortArray.Add(CString("Zebra"));
sortArray.Add(CString("Bat"));
sortArray.Add(CString("Apple"));
sortArray.Add(CString("Mango"));

for (int i = 0; i <= sortArray.GetUpperBound(); i++)
cout << sortArray[i] << endl;

sortArray.Sort();
cout << endl;

for (int j = 0; j <= sortArray.GetUpperBound(); j++)
cout << sortArray[j] << endl;
}

take care...
Sleepy | :zzz: Sleepy | :zzz:

utkarsh sharma
"Not everything that counts can be counted, and not everything that can be counted counts."
GeneralRemote Control App Pin
abcowherd2-Jan-04 2:05
abcowherd2-Jan-04 2:05 
GeneralRe: Remote Control App Pin
l a u r e n2-Jan-04 9:51
l a u r e n2-Jan-04 9:51 
QuestionDLL +PCI driver? Pin
nmelah2-Jan-04 0:16
nmelah2-Jan-04 0:16 
AnswerRe: DLL +PCI driver? Pin
Gary R. Wheeler2-Jan-04 14:15
Gary R. Wheeler2-Jan-04 14:15 
Generalaccess pci driver installation through C++ Pin
nmelah2-Jan-04 0:13
nmelah2-Jan-04 0:13 
GeneralRe: access pci driver installation through C++ Pin
dan o2-Jan-04 4:51
dan o2-Jan-04 4:51 
QuestionWhat files did i miss? Pin
Anonymous1-Jan-04 23:55
Anonymous1-Jan-04 23:55 
AnswerRe: What files did i miss? Pin
marzk5-Jan-04 11:09
marzk5-Jan-04 11:09 
GeneralApplication pauses Pin
misha_grewal1-Jan-04 21:46
misha_grewal1-Jan-04 21:46 
GeneralRe: Application pauses Pin
valikac2-Jan-04 6:08
valikac2-Jan-04 6:08 
GeneralDifference between malloc and LocalAlloc Pin
Member 2214801-Jan-04 21:11
Member 2214801-Jan-04 21:11 
GeneralRe: Difference between malloc and LocalAlloc Pin
Tibor Blazko1-Jan-04 21:35
Tibor Blazko1-Jan-04 21:35 
GeneralRe: Difference between malloc and LocalAlloc Pin
Member 2214801-Jan-04 21:57
Member 2214801-Jan-04 21:57 
GeneralRe: Difference between malloc and LocalAlloc Pin
Tibor Blazko2-Jan-04 0:40
Tibor Blazko2-Jan-04 0:40 
Generalflex.exe Pin
murali_utr1-Jan-04 20:50
murali_utr1-Jan-04 20:50 
GeneralRe: flex.exe Pin
murali_utr1-Jan-04 20:57
murali_utr1-Jan-04 20:57 
Generalproblem in windows programming...please help Pin
sam_mou1-Jan-04 20:12
sam_mou1-Jan-04 20:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.