C++ StringGrid + Bubble sort

Hello. Can I use bubble sort algorithm in my data surikiuos StringGrid when it is not just numbers, but letters?

Suppose a text file is scanned StringGrid looks like this:
1
2
3
4
5
================================================ 
No. | Name     | played | Won | Lost | Location | 
================================================ 
1 | Liet.Rytas | 7      | 7   | 0    |  2     | 
2 | Zalgiris   | 8      | 8   | 0    | 1      | 

Here's an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void BubbleSort (apvector <int> & num) 
( 
int i, j, flag = 1; / / set flag to 1 to start first pass 
int temp; / / holding variable 
int numLength = num.length (); 
for (i = 1 (i <= numLength) & & flag; i + +) 
  ( 
   flag = 0; 
   for (j = 0 j <(numLength -1) j + +) 
    ( 
     if (num [j +1]> num [j]) / / ascending order simply changes to < 
      ( 
       temp = num [j] / / swap elements 
       num [j] = num [j +1]; 
       num [j +1] = temp; 
       flag = 1; / / indicates that a swap occurred. 
      ) 
     ) 
   ) 
     return; / / Arrays are passed to functions by address, nothing is returned 
) 

How do I get it now correctly integrated into your program so that it fully operational?
Ordering must be done under the column "played."
Last edited on
Yes.

If you're using string from STL (std::string), simply treplace int with string.

If you're using C strings (null terminated char arrays), you compare them with strcmp, and assign them with strncpy. You need to be careful with the lengths.
Topic archived. No new replies allowed.