-2

I'm working on a basic DFS algorithm for my oriented graph in c++.

What i got, is a class Vertex which have a char value and a list of adjacence.

Given that, i'm trying to sort a list of object (in my case vertex, but let's say something else) by its value.

My class is something like that:

class Foo {
private:
    char x;
    list<Foo*> listOfChildrenObject;
};

let's say we got 5 Foo's object.

A,B,C,D,E

now, A is the father of every object in my program.

let's say i've inserted them in this way:

A (the father), D, C, B, E

and then, i want to print them in order:

A,B,C,D,E

and for that, i want to use listOfChildrenObject.sort() to do that.

there's a way to sort my list of object by the char value?

Asynchronousx
  • 81
  • 1
  • 8

1 Answers1

0

Ok, i think i got it.

sorry for the dumb and repeated question, i resolved adding a lambda function to my sort, and changing the list to a vector (i realized that i had no reason to use a list)

in this way:

std::sort(v.begin(), v.end(), [](Foo* a, Foo* b) {return a->getValue() < b->getValue(); });
Asynchronousx
  • 81
  • 1
  • 8