<?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[Welche Datenstruktur für Tabellen?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte eine Tabelle erstellen die verschieden sortiert werden soll.</p>
<p>Ich möchte Objekte erstellen, die zum Beispiel folgendes enthalten:</p>
<p>string bezeichner;<br />
int a, b, c;</p>
<p>Diese Objekte sollen nun nach Variablen des Objekts absteigend sortiert werden können (natürlich nicht gleichzeitig). Also sortieren nach a, b oder c.</p>
<p>Welche Datenstruktur ist hierfür am Besten geeignet und wie ist mit dieser dann ein Sortieren möglich?</p>
<p>Viele Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/150880/welche-datenstruktur-für-tabellen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 21:42:29 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/150880.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 21 Jun 2006 08:41:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 08:41:39 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich möchte eine Tabelle erstellen die verschieden sortiert werden soll.</p>
<p>Ich möchte Objekte erstellen, die zum Beispiel folgendes enthalten:</p>
<p>string bezeichner;<br />
int a, b, c;</p>
<p>Diese Objekte sollen nun nach Variablen des Objekts absteigend sortiert werden können (natürlich nicht gleichzeitig). Also sortieren nach a, b oder c.</p>
<p>Welche Datenstruktur ist hierfür am Besten geeignet und wie ist mit dieser dann ein Sortieren möglich?</p>
<p>Viele Grüße</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081860</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081860</guid><dc:creator><![CDATA[Bifinator]]></dc:creator><pubDate>Wed, 21 Jun 2006 08:41:39 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 08:46:29 GMT]]></title><description><![CDATA[<p>Für eine Tabellenzeile bietet sich ein struct/class an, für die komplette Tabelle ein vector&lt;zeile&gt; oder deque&lt;zeile&gt;. Sortieren kannst du dann mit den STL-Algorithmen (sort, stable_sort, partial_sort) und passend geschriebenen Vergleichsfunktionen:</p>
<pre><code class="language-cpp">struct zeile
{
  string bezeichner; 
  int a, b, c;
}

bool less_a(const zeile&amp; l, const zeile&amp; r)
{
  return l.a&lt;r.a;
}

//less_b, less_c, less_name analog dazu

...
vector&lt;zeile&gt; tabelle;
...
sort(tabelle.begin(),tabelle.end(),less_a);//sortieren nach Spalte a
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1081865</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081865</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 21 Jun 2006 08:46:29 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 08:52:45 GMT]]></title><description><![CDATA[<p>Cool, Danke.</p>
<p>Ich werd es mal so probieren.</p>
<p>Der Aufruf sort(tabelle.begin(),tabelle.end(),less_a); reicht um die gesamte Spalte zu sortieren?</p>
<p>Mir ist da noch was eingefallen. Die Ergebnisse möchte ich gerne in einer Datei speichern. Gibt es die Möglichkeit die Tabellen so in einer Datei zu speichern, dass die Datei in Excel schon formatiert geöffnet werden kann (bezeichner in Excel-Spalte A, a in Spalte B, usw.)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081870</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081870</guid><dc:creator><![CDATA[Bifinator]]></dc:creator><pubDate>Wed, 21 Jun 2006 08:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 08:55:22 GMT]]></title><description><![CDATA[<p>einfach als textdatei mit csv endung (war irgendwas nach dem motto comma seperated v..) speicher. Durch Kommata werden die einzelnen spalten getrennt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081873</guid><dc:creator><![CDATA[Delryn]]></dc:creator><pubDate>Wed, 21 Jun 2006 08:55:22 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 09:03:14 GMT]]></title><description><![CDATA[<p>Bifinator schrieb:</p>
<blockquote>
<p>Der Aufruf sort(tabelle.begin(),tabelle.end(),less_a); reicht um die gesamte Spalte zu sortieren?</p>
</blockquote>
<p>Der sortiert sogar die komplette Tabelle gemäß der Spalte a <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<blockquote>
<p>Mir ist da noch was eingefallen. Die Ergebnisse möchte ich gerne in einer Datei speichern. Gibt es die Möglichkeit die Tabellen so in einer Datei zu speichern, dass die Datei in Excel schon formatiert geöffnet werden kann (bezeichner in Excel-Spalte A, a in Spalte B, usw.)?</p>
</blockquote>
<p>Wie Delryn sagte: Comma Seperated Values - speichere die Elemente hintereinander durch Kommas getrennt in einer Textdatei:</p>
<pre><code class="language-cpp">ofstream fout(&quot;out.csv&quot;);
for(vector&lt;zeile&gt;::iterator p = tabelle.begin();p!=tabelle.end();++p)
  fout&lt;&lt;p-&gt;bezeichner&lt;&lt;&quot;,&quot;&lt;&lt;p-&gt;a&lt;&lt;&quot;,&quot;&lt;&lt;p-&gt;b&lt;&lt;&quot;,&quot;&lt;&lt;p-&gt;c&lt;&lt;&quot;\n&quot;;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1081882</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081882</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Wed, 21 Jun 2006 09:03:14 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 09:24:38 GMT]]></title><description><![CDATA[<p>Vielen Dank für eure Hilfe.</p>
<p>Ich werd das nun mal in Angriff nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081905</guid><dc:creator><![CDATA[Bifinator]]></dc:creator><pubDate>Wed, 21 Jun 2006 09:24:38 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 10:04:00 GMT]]></title><description><![CDATA[<p>Ich habe noch eine Frage zu struct.</p>
<p>Ich will die Elemente die in struct gespeichert werden sollen aus einer Textdatei einlesen, weiss aber nicht vorher wie viele das sind. Wie initialisiere ich nun struct?</p>
<p>Normalerweise macht man ja:</p>
<pre><code class="language-cpp">struct a,b;

a.bla = ...
a.blu = ...

usw.
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1081940</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081940</guid><dc:creator><![CDATA[Bifinator]]></dc:creator><pubDate>Wed, 21 Jun 2006 10:04:00 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 10:14:54 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>vermutlich brauchst du ein dynamisches Array, dafür kannst du zum Beispiel std::vector nehmen.</p>
<pre><code class="language-cpp">#include &lt;vector&gt;
...
struct record {... };
std::vector&lt;record&gt; table;
...
record new;
// Daten für new einlesen
table.push_back(new); // neuen Datensatz in dynamisches Array anfügen
</code></pre>
<p>Vorteil : du kannst gleich die Standard-Funktionen zum sortieren benutzen.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1081947</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1081947</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Wed, 21 Jun 2006 10:14:54 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 11:40:06 GMT]]></title><description><![CDATA[<p>Habe mal wieder ein Problem.</p>
<p>Ich bekomme folgende Fehlermeldung:</p>
<p>no matching function for call to ‘sort(__gnu_cxx::__normal_iterator&lt;Cartography::bundesland*, std::vector&lt;Cartography::bundesland, std::allocator<a href="Cartography::bundesland" rel="nofollow">Cartography::bundesland</a> &gt; &gt;, __gnu_cxx::__normal_iterator&lt;Cartography::bundesland*, std::vector&lt;Cartography::bundesland, std::allocator<a href="Cartography::bundesland" rel="nofollow">Cartography::bundesland</a> &gt; &gt;, &lt;unknown type&gt;)’<br />
/usr/include/c++/4.0.2/bits/stl_algo.h:2591: note: candidates are: void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator&lt;Cartography::bundesland*, std::vector&lt;Cartography::bundesland, std::allocator<a href="Cartography::bundesland" rel="nofollow">Cartography::bundesland</a> &gt; &gt;, _Compare = bool (Cartography::*)(const Cartography::bundesland&amp;, const Cartography::bundesland&amp;)]</p>
<p>Woran kann das liegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082015</guid><dc:creator><![CDATA[Bifinator]]></dc:creator><pubDate>Wed, 21 Jun 2006 11:40:06 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 11:45:29 GMT]]></title><description><![CDATA[<p>Wie wärs, wenn du uns mal den Code dazu zeigst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082022</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082022</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 21 Jun 2006 11:45:29 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 11:47:53 GMT]]></title><description><![CDATA[<p>Sorry, der Code ist analog zu oben</p>
<pre><code class="language-cpp">struct zeile
{
  string bezeichner;
  int a, b, c;
}

bool less_a(const zeile&amp; l, const zeile&amp; r)
{
  return l.a&lt;r.a;
}

//less_b, less_c, less_name analog dazu

...
vector&lt;zeile&gt; tabelle;
...
sort(tabelle.begin(),tabelle.end(),less_a);//sortieren nach Spalte a
</code></pre>
<p>Wenn ich sort(...) aufrufe erhalte ich den gerade genannten Fehler.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082025</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082025</guid><dc:creator><![CDATA[Bifinator]]></dc:creator><pubDate>Wed, 21 Jun 2006 11:47:53 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 11:59:47 GMT]]></title><description><![CDATA[<p>Irgendwie kann das nicht der Code sein. Wo ist denn hier Cartography::bundesland?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082036</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082036</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 21 Jun 2006 11:59:47 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 12:04:24 GMT]]></title><description><![CDATA[<blockquote>
<p>_Compare = bool (Cartography::*)(const Cartography::bundesland&amp;, const Cartography::bundesland&amp;</p>
</blockquote>
<p>ich würde mal ganz frech darauf tippen, dass deine vergleichsfunktion eine nichtstatische memberfunktion ist. das kann (nat.) nicht funktionieren. mach die funktion statisch oder benutz einen funktor.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082039</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082039</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 21 Jun 2006 12:04:24 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 12:09:04 GMT]]></title><description><![CDATA[<p>Der Code ist analog zu meinem nur das die Variablen umbenannt wurden.</p>
<p>Meiner ist so:</p>
<pre><code class="language-cpp">void Cartography::evaluateFederalState(char name[])
{

	vector&lt;bundesland&gt; v;

	bundesland b;

	string line, temp, query;
	int pos;

	//Filterung der relevanten Daten aus Textdatei und Speicherung im Vector
	while(getline(sampleSource,line))
	{
		temp = line;
		pos = temp.find(&quot;###&quot;);
		if(pos &gt; -1)
		{
		    temp.erase(pos);
			b.blName = temp;
			line.erase(0,pos+3);
			temp = line;

			pos = temp.find(&quot;###&quot;);
			if(pos &gt; -1)
			{
				temp.erase(pos);
				b.flaeche = atof(temp.c_str());
				line.erase(0,pos+3);	
				b.einwohner = atof(line.c_str());
			}
		}

		//Objekt in Vector schreiben		
		v.push_back(b);
	}	

...    
sort(v.begin(),v.end(),less_flaeche);
}

bool Cartography::less_flaeche(const bundesland&amp; l, const bundesland&amp; r)
{
  	return l.flaeche &lt; r.flaeche; 
}
</code></pre>
<p>Die Header-Datei sieht so aus:</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;

using namespace std;

class Cartography
{
	private:
		//Zeiger auf MySQL-Verbindungs-Handle
		MYSQL *conn;

		ifstream sampleSource;
		ofstream destination;

		struct bundesland
		{
			string blName;
			float flaeche, einwohner, flaechenFaktor, einwohnerFaktor; 	
			int gefUnternehmen;
	};

	public:
		Cartography()
		{
			//einlesen der Textdatei mit den Bundeslanddaten
			sampleSource.open(&quot;cartography.txt&quot;);

			if(!sampleSource)
		    {
		        cerr &lt;&lt; &quot;\nFehler beim Oeffnen der Datei Fax.txt. \nDie Datei existiert&quot; 
		             &lt;&lt; &quot; moeglicherweise nicht.\n&quot;;
		        exit(1);
		    }
		}

		//Auswertung
		void evaluateFederalState(char name []);	

		//Hilfsmethoden zur Sortierung der Ergebnisse
		bool less_flaeche(const bundesland&amp; l, const bundesland&amp; r);

};
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1082043</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082043</guid><dc:creator><![CDATA[Bifinator]]></dc:creator><pubDate>Wed, 21 Jun 2006 12:09:04 GMT</pubDate></item><item><title><![CDATA[Reply to Welche Datenstruktur für Tabellen? on Wed, 21 Jun 2006 12:13:37 GMT]]></title><description><![CDATA[<blockquote>
<p>ich würde mal ganz frech darauf tippen, dass deine vergleichsfunktion eine nichtstatische memberfunktion ist. das kann (nat.) nicht funktionieren. mach die funktion statisch oder benutz einen funktor.</p>
</blockquote>
<p>Das scheint es gewesen zu sein, es funktioniert nun anscheined.</p>
<p>Vielen Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1082049</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1082049</guid><dc:creator><![CDATA[Bifinator]]></dc:creator><pubDate>Wed, 21 Jun 2006 12:13:37 GMT</pubDate></item></channel></rss>