<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[vector sortieren und unique ??? funzt nicht]]></title><description><![CDATA[<p>Hi<br />
Ich habe folgende Strukturen:</p>
<pre><code class="language-cpp">struct person
{
  string vname;
  string nname;
  int gebdate;
};

vector&lt;person&gt; p1
vector&lt;person&gt; p2

bool compare_persons (const person &amp;a, const person &amp;b)
{
    return a.gebdate &lt; b.gebdate;
}
bool unique_persons(const person &amp;a, const person &amp;b)
{
 return (a.nname == b.nname &amp;&amp; a.gebdate == b.gebdate);
}

 sort(p1.begin(),p1.end(),compare_persons);
 sort(p2.begin(),p2.end(),compare_persons);

 unique(p2.begin(),p2.end(),unique_persons);
 unique(p2.begin(),p2.end(),unique_persons);
</code></pre>
<p>Das Problem ist das sort und unique nicht funktioniert? Er sortiert einfach nicht nach dem Geburtsdatum aber wieso?<br />
Bitte um Hilfe oder geht das sort, unique nur in der List. Glaub aber nicht.</p>
<p>danke<br />
mfg<br />
1metal3</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/170053/vector-sortieren-und-unique-funzt-nicht</link><generator>RSS for Node</generator><lastBuildDate>Thu, 17 Sep 2026 00:05:24 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/170053.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Jan 2007 11:35:06 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to vector sortieren und unique ??? funzt nicht on Thu, 11 Jan 2007 11:35:06 GMT]]></title><description><![CDATA[<p>Hi<br />
Ich habe folgende Strukturen:</p>
<pre><code class="language-cpp">struct person
{
  string vname;
  string nname;
  int gebdate;
};

vector&lt;person&gt; p1
vector&lt;person&gt; p2

bool compare_persons (const person &amp;a, const person &amp;b)
{
    return a.gebdate &lt; b.gebdate;
}
bool unique_persons(const person &amp;a, const person &amp;b)
{
 return (a.nname == b.nname &amp;&amp; a.gebdate == b.gebdate);
}

 sort(p1.begin(),p1.end(),compare_persons);
 sort(p2.begin(),p2.end(),compare_persons);

 unique(p2.begin(),p2.end(),unique_persons);
 unique(p2.begin(),p2.end(),unique_persons);
</code></pre>
<p>Das Problem ist das sort und unique nicht funktioniert? Er sortiert einfach nicht nach dem Geburtsdatum aber wieso?<br />
Bitte um Hilfe oder geht das sort, unique nur in der List. Glaub aber nicht.</p>
<p>danke<br />
mfg<br />
1metal3</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1207811</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1207811</guid><dc:creator><![CDATA[1metal3]]></dc:creator><pubDate>Thu, 11 Jan 2007 11:35:06 GMT</pubDate></item><item><title><![CDATA[Reply to vector sortieren und unique ??? funzt nicht on Thu, 11 Jan 2007 12:10:57 GMT]]></title><description><![CDATA[<p>Wie genau äußert sich denn das Problem? sort() sollte eigentlich das richtige Ergebnis liefern.</p>
<p>Dein Problem könnte höchstens sein, daß unique() nicht in der Lage ist, Objekte physikalisch zu löschen. Deshalb gibt es einen Iterator auf das neue Ende des Bereiches zurück und lässt alles dahinter unberührt (auftretende Lücken, wenn ein Duplikat rausgeworfen wurde, werden mit den nachfolgenden Elementen überschrieben) - löschen mußt du diesen Schwanz dann selber:</p>
<pre><code class="language-cpp">p1.erase(unique(p1.begin(),p1.end(),unique_persons),p1.end());
</code></pre>
<p>PS: Ist es eigentlich Absicht, daß du zweimal den selben Vector an unique übergibst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1207836</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1207836</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 11 Jan 2007 12:10:57 GMT</pubDate></item><item><title><![CDATA[Reply to vector sortieren und unique ??? funzt nicht on Thu, 11 Jan 2007 12:56:16 GMT]]></title><description><![CDATA[<p>danke<br />
bei unique soll natürlich einmal p1 und einmal p2 drankkommen.</p>
<p>Problem ist einfach das die Ausgabe nicht sortiert nach Geburtsdatum ist.</p>
<p>ich teste mal weiter, mal sehen,</p>
<p>danke</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1207880</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1207880</guid><dc:creator><![CDATA[1metal3]]></dc:creator><pubDate>Thu, 11 Jan 2007 12:56:16 GMT</pubDate></item><item><title><![CDATA[Reply to vector sortieren und unique ??? funzt nicht on Thu, 11 Jan 2007 13:02:44 GMT]]></title><description><![CDATA[<p>1metal3 schrieb:</p>
<blockquote>
<p>Problem ist einfach das die Ausgabe nicht sortiert nach Geburtsdatum ist.</p>
</blockquote>
<p>Da hast du den Fehler woanders gemacht (sort() sortiert korrekt, und dein Vergleichsattribut sieht auch gut aus) - zeig doch mal ein etwas ausführlicheres Beispiel.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1207890</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1207890</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Thu, 11 Jan 2007 13:02:44 GMT</pubDate></item><item><title><![CDATA[Reply to vector sortieren und unique ??? funzt nicht on Fri, 12 Jan 2007 17:18:10 GMT]]></title><description><![CDATA[<p>das unique mit erase hat die Lösung gebracht<br />
vielen dank<br />
mfg<br />
1metal3</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1208911</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1208911</guid><dc:creator><![CDATA[1metal3]]></dc:creator><pubDate>Fri, 12 Jan 2007 17:18:10 GMT</pubDate></item></channel></rss>