Sorting

struct space
{
string name;
int value;
} a[5200] ;

i want to sort the array by string name , how can i do it ?
You should get an idea from this example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Example program
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
    std::string name[] = {"Hello", "World", "!!!"};
    int z = sizeof(name) / sizeof(name[0]); //Get the array size

    sort(name,name+z); //Use the start and end like this

    for(int y = 0; y < z; y++)
        std::cout << name[y] << std::endl;
}

Last edited on
Topic archived. No new replies allowed.