1. Dashboard
  2. Forum
    1. Unerledigte Themen
  3. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team-Mitglieder
    4. Trophäen
    5. Mitgliedersuche
  4. Tutorial Bereich
  • Anmelden
  • Registrieren
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Lexikon
  • Erweiterte Suche
  1. Informatik Forum
  2. Webmaster & Internet
  3. Entwicklung

sorting linked list of objects

  • phyllis
  • 10. April 2006 um 15:01
  • Unerledigt
  • phyllis
    2
    phyllis
    Mitglied
    Punkte
    15
    Beiträge
    2
    • 10. April 2006 um 15:01
    • #1

    I have a problem I hope somebody kan help me with. I have a number of objects of type

    Code
    class code
        {
        public:
              string file;
              vector<string> files;
              int start, size;
    
              code(){}
              ~code(){}
              bool operator< (const code *a)  { return this->files.size() >= a->files.size(); };
        };
    Alles anzeigen



    that I want to put in a STL-list

    Code
    list<code *> tmp_list;

    [FONT=&quot]

    and then I want to sort them so that the code object with the biggest vector<string> files comes first

    [/FONT]

    Code
    tmp_list.sort();

    [FONT=&quot]

    But this doesn't work!? Instead I get a list sorted after int start... Can somebody see what I am doing wrong here? Or is the problem somewhere else in my program?
    [/FONT]

  • kubuntu
    6
    kubuntu
    Mitglied
    Reaktionen
    2
    Punkte
    352
    Beiträge
    65
    • 10. April 2006 um 17:02
    • #2

    you are sorting code*, not the code objects.

    use list<code> instead.


  • phyllis
    2
    phyllis
    Mitglied
    Punkte
    15
    Beiträge
    2
    • 10. April 2006 um 17:15
    • #3

    thanks for answering. I was guessing it had something to do with this...
    but what if I want to use a list of pointers, is there no way to sort the list then?

  • Spockman
    5
    Spockman
    Mitglied
    Punkte
    210
    Beiträge
    41
    • 10. April 2006 um 21:25
    • #4
    Zitat von phyllis

    but what if I want to use a list of pointers, is there no way to sort the list then?

    There are many - however, why are you using pointers in the first place? You don't seem to need polymorphism. To avoid copying, declare parameters as references.

  • kubuntu
    6
    kubuntu
    Mitglied
    Reaktionen
    2
    Punkte
    352
    Beiträge
    65
    • 10. April 2006 um 22:35
    • #5

    .... or use boost :: ptr_list


  • Maximilian Rupp 27. Dezember 2024 um 12:06

    Hat das Thema aus dem Forum Programmieren nach Entwicklung verschoben.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!

Benutzerkonto erstellen Anmelden

Benutzer online in diesem Thema

  • 1 Besucher

Rechtliches

Impressum

Datenschutzerklärung