1. Weiterleitung zu NetzLiving.de
  2. Forum
    1. Unerledigte Themen
  3. zum neuen Forum
  • Anmelden
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Erweiterte Suche
  1. Informatik Forum
  2. Webmaster & Internet
  3. Entwicklung

sorting linked list of objects

  • phyllis
  • 10. April 2006 um 15:01
  • Unerledigt
Hallo zusammen,

das Informatik-Forum geht in den Archivmodus, genaue Informationen kann man der entsprechenden Ankündigung entnehmen. Als Dankeschön für die Treue bekommt man von uns einen Gutscheincode (informatikforum30) womit man bei netzliving.de 30% auf das erste Jahr sparen kann. (Genaue Infos sind ebenfalls in der Ankündigung)

Vielen Dank für die Treue und das Verständnis!
  • phyllis
    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
    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
    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
    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
    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.

  1. Datenschutzerklärung
  2. Impressum