You'll want to use an stl data type (for example, the vector or deque). Just push all the names on the vector, then call the sort function to sort them all.
http://www.msoe.edu/eecs/ce/courseinfo/stl/sort.htm
2006-10-06 09:31:52
·
answer #1
·
answered by arnie 2
·
0⤊
0⤋
How are the names organized-- that'll make a difference.
(e.g. tree, array, collection, etc.)
Look for sorting functions in C++ library-- I'm sure there a some.
You can also write a buble sort (if you really have to)
2006-10-06 16:19:00
·
answer #2
·
answered by dapixelator 6
·
0⤊
0⤋
You need to use qsort():
#include
#include
#include
int compare( const void * p1, const void * p2 )
{
return strcmp( *(const char**)p1, *(const char **)p2 );
}
void print_sorted( char ** names, int sz )
{
qsort( names, sz, sizeof( char*), compare );
for( int i = 0; i < sz; i++ )
printf( "%s\n", names[i] );
}
int main( int ac, char ** av )
{
char *names[] =
{
"wow",
"aaaaa",
"zzzzz",
"bbbbb",
"bububu",
};
print_sorted( names, 5 );
}
2006-10-06 16:43:05
·
answer #3
·
answered by alakit013 5
·
1⤊
0⤋