<?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[stable_sort]]></title><description><![CDATA[<p>Hi,,</p>
<p>folgendes Programm habe ich geschrieben:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include&lt;algorithm&gt;
#include&lt;deque&gt;
#include&lt;functional&gt;
#include&lt;string&gt;
using namespace std;

struct daten
{
	string name;
	string wohnort;
};

ostream&amp; operator&lt;&lt;(ostream&amp; os,daten&amp; d)
{
	os&lt;&lt;d.name&lt;&lt;&quot; wohnt in &quot;&lt;&lt;d.wohnort&lt;&lt;&quot;.&quot;&lt;&lt;endl;
	return os;
}

daten init()
{
	daten temp;
	static int i=0;
	i++;
	if(i==1) { temp.name=&quot;Bernd&quot;;temp.wohnort=&quot;Rostock&quot;; }
	if(i==2) { temp.name=&quot;Kai&quot;;temp.wohnort=&quot;Rostock&quot;; }
	if(i==3) { temp.name=&quot;Tanja&quot;;temp.wohnort=&quot;Magdeburg&quot;; }
	if(i==4) { temp.name=&quot;Chris&quot;;temp.wohnort=&quot;Rostock&quot;; }
	if(i==5) { temp.name=&quot;Tina&quot;;temp.wohnort=&quot;Stuttgart&quot;; }
	return(temp);
}

int main()
{
	deque&lt;daten&gt; container(5);
	deque&lt;daten&gt;::iterator iter;
	generate(container.begin(),container.end(),init);
	stable_sort(container.begin(),container.end(),greater&lt;string&gt;());                                   
                                        //funktioniert nicht ^^^^^^^^
	for(iter=container.begin();iter!=container.end();iter++)
		cout&lt;&lt;*iter&lt;&lt;endl;
	return 0;
}
</code></pre>
<p>Ich würde gerne erst nach dem Wohnort sortieren, dann nach dem Namen. Damit die relative Reihenfolge erhalten bleibt, möchte ich 2 stable_sort-Algorithmen nutzen. Nur wie formuliere ich den Algorithmus, dass er z.B. nach dme Wohnort suchen soll. Dem Vergleichsobjekt kann man ja nur den Datentyp der zu sortierenden Werte übergeben, wie z.B. &quot;string&quot;, und nicht &quot;daten.wohnort&quot;.</p>
<p>Kann mir jemand helfen??</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/125398/stable_sort</link><generator>RSS for Node</generator><lastBuildDate>Mon, 24 Aug 2026 07:30:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/125398.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 06 Nov 2005 13:25:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to stable_sort on Sun, 06 Nov 2005 13:25:49 GMT]]></title><description><![CDATA[<p>Hi,,</p>
<p>folgendes Programm habe ich geschrieben:</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include&lt;algorithm&gt;
#include&lt;deque&gt;
#include&lt;functional&gt;
#include&lt;string&gt;
using namespace std;

struct daten
{
	string name;
	string wohnort;
};

ostream&amp; operator&lt;&lt;(ostream&amp; os,daten&amp; d)
{
	os&lt;&lt;d.name&lt;&lt;&quot; wohnt in &quot;&lt;&lt;d.wohnort&lt;&lt;&quot;.&quot;&lt;&lt;endl;
	return os;
}

daten init()
{
	daten temp;
	static int i=0;
	i++;
	if(i==1) { temp.name=&quot;Bernd&quot;;temp.wohnort=&quot;Rostock&quot;; }
	if(i==2) { temp.name=&quot;Kai&quot;;temp.wohnort=&quot;Rostock&quot;; }
	if(i==3) { temp.name=&quot;Tanja&quot;;temp.wohnort=&quot;Magdeburg&quot;; }
	if(i==4) { temp.name=&quot;Chris&quot;;temp.wohnort=&quot;Rostock&quot;; }
	if(i==5) { temp.name=&quot;Tina&quot;;temp.wohnort=&quot;Stuttgart&quot;; }
	return(temp);
}

int main()
{
	deque&lt;daten&gt; container(5);
	deque&lt;daten&gt;::iterator iter;
	generate(container.begin(),container.end(),init);
	stable_sort(container.begin(),container.end(),greater&lt;string&gt;());                                   
                                        //funktioniert nicht ^^^^^^^^
	for(iter=container.begin();iter!=container.end();iter++)
		cout&lt;&lt;*iter&lt;&lt;endl;
	return 0;
}
</code></pre>
<p>Ich würde gerne erst nach dem Wohnort sortieren, dann nach dem Namen. Damit die relative Reihenfolge erhalten bleibt, möchte ich 2 stable_sort-Algorithmen nutzen. Nur wie formuliere ich den Algorithmus, dass er z.B. nach dme Wohnort suchen soll. Dem Vergleichsobjekt kann man ja nur den Datentyp der zu sortierenden Werte übergeben, wie z.B. &quot;string&quot;, und nicht &quot;daten.wohnort&quot;.</p>
<p>Kann mir jemand helfen??</p>
]]></description><link>https://www.c-plusplus.net/forum/post/909443</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/909443</guid><dc:creator><![CDATA[AJ_Styles]]></dc:creator><pubDate>Sun, 06 Nov 2005 13:25:49 GMT</pubDate></item><item><title><![CDATA[Reply to stable_sort on Sun, 06 Nov 2005 13:34:17 GMT]]></title><description><![CDATA[<p>Sorry für das doppelte Post,,</p>
]]></description><link>https://www.c-plusplus.net/forum/post/909459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/909459</guid><dc:creator><![CDATA[AJ_Styles]]></dc:creator><pubDate>Sun, 06 Nov 2005 13:34:17 GMT</pubDate></item><item><title><![CDATA[Reply to stable_sort on Sun, 06 Nov 2005 13:38:54 GMT]]></title><description><![CDATA[<p>Schreib dir eine eigene Vergleichsklasse. Für die überlädts du bool operator () (const daten&amp; l, const daten&amp; r) und gut is.<br />
Übrigens benutzt man normalerweise den Präfixinkrement (++iter statt iter++).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/909465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/909465</guid><dc:creator><![CDATA[.filmor]]></dc:creator><pubDate>Sun, 06 Nov 2005 13:38:54 GMT</pubDate></item><item><title><![CDATA[Reply to stable_sort on Mon, 07 Nov 2005 08:00:45 GMT]]></title><description><![CDATA[<p>Hier geht's weiter: <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-125397.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-125397.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/910259</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/910259</guid><dc:creator><![CDATA[HumeSikkins]]></dc:creator><pubDate>Mon, 07 Nov 2005 08:00:45 GMT</pubDate></item></channel></rss>