<?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[Die fehlenden Verbindungen der Variablen mit Algorithmus?]]></title><description><![CDATA[<p>Erbitte um schnelle Hilfe!</p>
<p>Dies ist ein c++ Programm über den Algorithmus Shellsort. Der funktioniert an sich, jedoch fehlt die Verknüpfung von den Zahlen, die über Datei eingelesen werden. Sie müssen in das Feld geschrieben werden, um sortiert werden zu können.<br />
Wie bekomme ich das hin? Es reichen auch erstmal die ersten Zehn zahlen, die dann von der DAtei aus sortiert werden. Wird beim Menü oben das Programm bei drücken von 3(beenden) auch wirklich beendet?<br />
Kann es jemand vervollstänndigen?<br />
Ich bin so unglücklich. Morgen muss die Dokumentation geschrieben werden...[cpp]</p>
<p>#include &lt;iostream.h&gt;<br />
#include &lt;iomanip.h&gt;<br />
#include &lt;fstream.h&gt;<br />
#include &lt;string.h&gt;</p>
<p>void manuellezahleneingabe();<br />
void dateilesen();</p>
<p>int main(){</p>
<p>char antw;</p>
<p>do<br />
{(cin.clear();<br />
cout&lt;&lt;&quot;\n&quot;;<br />
cout&lt;&lt;&quot;SHELLSORT SORTIERALGORITHMUS&quot;;<br />
cout&lt;&lt;&quot;\n\n Bitte Auswählen:\n&quot;;<br />
cout&lt;&lt;&quot;Manuelle Zahleneingabe (1)\n&quot;;<br />
cout&lt;&lt;&quot;Lesen einer existierenden Datei (2)\n&quot;;<br />
cout&lt;&lt;&quot;Programm Beenden (3)\n&quot;;</p>
<p>switch (antw=getch()) //Menü<br />
{case '1': void manuellezahleneingabe; break;<br />
case '2': void dateilesen; break;<br />
case '3': break; //Ende Programm<br />
default: cout&lt;&lt;&quot;falsche Auswahl\n&quot;;break;<br />
}<br />
while (antw!='3')<br />
cout&lt;&lt;&quot;\n&quot;;<br />
getch();<br />
for (antw='3')<br />
exit(3);<br />
}</p>
<p>}<br />
// Ende Menü</p>
<p>void manuellezahleneingabe()<br />
{<br />
float *arrZahlen, t;<br />
bool weiter;<br />
int j, z=0, iStart, i, iDist, iNumbers ; //Zählvariable z für Auswertung Laufzeitverhalten</p>
<p>cout &lt;&lt;&quot;SHELLSORT SORTIERALGORITHMUS&quot;;</p>
<p>cout &lt;&lt; &quot;\n\nBitte Anzahl der Zahlen eingeben: &quot;;<br />
cin &gt;&gt; iNumbers;</p>
<p>arrZahlen = new float[iNumbers]; // Dynamisches Array anlegen</p>
<p>for(int i=0;i&lt;iNumbers;i++)<br />
{<br />
cout &lt;&lt; &quot;\nBitte &quot; &lt;&lt; (i+1) &lt;&lt; &quot;. Zahl eingeben: &quot;;<br />
cin &gt;&gt; arrZahlen[i];<br />
}<br />
cout &lt;&lt; &quot;\nBitte Start-Inkrement-Wert eingeben: &quot;;<br />
cin &gt;&gt; iStart;</p>
<p>do{<br />
cout &lt;&lt; &quot;\nBitte Inkrement-Distanz eingeben: &quot;;<br />
cin &gt;&gt; iDist;<br />
}<br />
while((iStart-1)%iDist!=0); // Damit bei iStart-x*iDist mind einmal 1 rauskommt</p>
<p>// Start ShellSort<br />
for(int h=iStart;h&gt;0;h=h-iDist) // Schrittweiten<br />
{<br />
//cout &lt;&lt; &quot;\n\n\n h: &quot; &lt;&lt; h;</p>
<p>for(i=h; i&lt;iNumbers; i++)<br />
{<br />
j = i;<br />
t = arrZahlen[i]; //<br />
weiter = true;</p>
<p>/*<br />
cout &lt;&lt; &quot;\nt: &quot; &lt;&lt; t &lt;&lt; &quot; i: &quot; &lt;&lt; i &lt;&lt; &quot; j: &quot; &lt;&lt; j; //Zwischenauswertung für Testphase</p>
<p>for(int x=0;x&lt;iNumbers;x++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[x];<br />
}<br />
*/</p>
<p>while(weiter &amp;&amp; (arrZahlen[j-h]&gt;t)) // Vertauschung, wenn Vorgängerzahlen größer als Nachfolger<br />
{<br />
arrZahlen[j] = arrZahlen[j-h];<br />
j -= h;<br />
weiter = (j&gt;=h);<br />
z++;<br />
}<br />
arrZahlen[j] = t; // Pivotelement an neuen Platz (kleineren Platz) schreiben</p>
<p>/* //Zwischenauswertung für Testphase<br />
cout &lt;&lt; &quot;\n&quot;;</p>
<p>for(int x=0;x&lt;iNumbers;x++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[x];<br />
}</p>
<p>cout &lt;&lt; &quot;\n\n\n&quot;;<br />
*/<br />
}<br />
}</p>
<p>cout &lt;&lt; &quot;\nAusgabe: &quot;;<br />
for(i=0;i&lt;iNumbers;i++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[i]; //Ausgabe der sortierten Zahlen</p>
<p>}<br />
cout &lt;&lt;&quot;\nNotwendige Sortierschritte: &quot; &lt;&lt;z; //Auswertung der benötigten Sortiervorgänge</p>
<p>cin &gt;&gt; i;</p>
<p>//speichern????<br />
}</p>
<p>void dateilesen()<br />
float *arrZahlen, t;<br />
bool weiter;<br />
int j, z=0, iStart, i, iDist, iNumbers ; //Zählvariable z für Auswertung Laufzeitverhalten<br />
using namespace std;</p>
<p>cout &lt;&lt;&quot;SHELLSORT SORTIERALGORITHMUS&quot;;<br />
{<br />
ifstream datei( &quot;zahlendatei.txt&quot;, ios::in );<br />
string speicher;<br />
while (datei;<br />
{<br />
//getline( &quot;zahlendatei&quot;, speicher );</p>
<p>cout &lt;&lt; speicher;}</p>
<p>cin &gt;&gt; speicher;</p>
<p>arrZahlen = new float[iNumbers]; // Dynamisches Array anlegen</p>
<p>for(int i=0;i&lt;iNumbers;i++)</p>
<p>{</p>
<p>cout &lt;&lt; &quot;\nBitte Start-Inkrement-Wert eingeben: &quot;;<br />
cin &gt;&gt; iStart;</p>
<p>do{<br />
cout &lt;&lt; &quot;\nBitte Inkrement-Distanz eingeben: &quot;;<br />
cin &gt;&gt; iDist;<br />
}<br />
while((iStart-1)%iDist!=0); // Damit bei iStart-x*iDist mind einmal 1 rauskommt</p>
<p>// Start ShellSort<br />
for(int h=iStart;h&gt;0;h=h-iDist) // Schrittweiten<br />
{<br />
//cout &lt;&lt; &quot;\n\n\n h: &quot; &lt;&lt; h;</p>
<p>for(i=h; i&lt;iNumbers; i++)<br />
{<br />
j = i;<br />
t = arrZahlen[i]; //<br />
weiter = true;</p>
<p>/*<br />
cout &lt;&lt; &quot;\nt: &quot; &lt;&lt; t &lt;&lt; &quot; i: &quot; &lt;&lt; i &lt;&lt; &quot; j: &quot; &lt;&lt; j; //Zwischenauswertung für Testphase</p>
<p>for(int x=0;x&lt;iNumbers;x++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[x];<br />
}<br />
*/</p>
<p>while(weiter &amp;&amp; (arrZahlen[j-h]&gt;t)) // Vertauschung, wenn Vorgängerzahlen größer als Nachfolger<br />
{<br />
arrZahlen[j] = arrZahlen[j-h];<br />
j -= h;<br />
weiter = (j&gt;=h);<br />
z++;<br />
}<br />
arrZahlen[j] = t; // Pivotelement an neuen Platz (kleineren Platz) schreiben</p>
<p>/* //Zwischenauswertung für Testphase<br />
cout &lt;&lt; &quot;\n&quot;;</p>
<p>for(int x=0;x&lt;iNumbers;x++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[x];<br />
}</p>
<p>cout &lt;&lt; &quot;\n\n\n&quot;;<br />
*/<br />
}<br />
}</p>
<p>cout &lt;&lt;&quot;\nNotwendige Sortierschritte: &quot; &lt;&lt;z; //Auswertung der benötigten Sortiervorgänge</p>
<p>// Schreiben der sorteirten Datei in sortzahlen.txt</p>
<p>ofstream datei;<br />
datei open(&quot;sortzahlen.txt&quot;, ios::out);<br />
datei &lt;&lt; &quot;schleife für sortierte Zahlen, die irgendwo vorliegen&quot; &lt;&lt; endl;<br />
datei.close();</p>
<p>//speichern????<br />
}<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/152236/die-fehlenden-verbindungen-der-variablen-mit-algorithmus</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 23:41:03 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/152236.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 Jul 2006 13:31:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Die fehlenden Verbindungen der Variablen mit Algorithmus? on Tue, 04 Jul 2006 13:31:26 GMT]]></title><description><![CDATA[<p>Erbitte um schnelle Hilfe!</p>
<p>Dies ist ein c++ Programm über den Algorithmus Shellsort. Der funktioniert an sich, jedoch fehlt die Verknüpfung von den Zahlen, die über Datei eingelesen werden. Sie müssen in das Feld geschrieben werden, um sortiert werden zu können.<br />
Wie bekomme ich das hin? Es reichen auch erstmal die ersten Zehn zahlen, die dann von der DAtei aus sortiert werden. Wird beim Menü oben das Programm bei drücken von 3(beenden) auch wirklich beendet?<br />
Kann es jemand vervollstänndigen?<br />
Ich bin so unglücklich. Morgen muss die Dokumentation geschrieben werden...[cpp]</p>
<p>#include &lt;iostream.h&gt;<br />
#include &lt;iomanip.h&gt;<br />
#include &lt;fstream.h&gt;<br />
#include &lt;string.h&gt;</p>
<p>void manuellezahleneingabe();<br />
void dateilesen();</p>
<p>int main(){</p>
<p>char antw;</p>
<p>do<br />
{(cin.clear();<br />
cout&lt;&lt;&quot;\n&quot;;<br />
cout&lt;&lt;&quot;SHELLSORT SORTIERALGORITHMUS&quot;;<br />
cout&lt;&lt;&quot;\n\n Bitte Auswählen:\n&quot;;<br />
cout&lt;&lt;&quot;Manuelle Zahleneingabe (1)\n&quot;;<br />
cout&lt;&lt;&quot;Lesen einer existierenden Datei (2)\n&quot;;<br />
cout&lt;&lt;&quot;Programm Beenden (3)\n&quot;;</p>
<p>switch (antw=getch()) //Menü<br />
{case '1': void manuellezahleneingabe; break;<br />
case '2': void dateilesen; break;<br />
case '3': break; //Ende Programm<br />
default: cout&lt;&lt;&quot;falsche Auswahl\n&quot;;break;<br />
}<br />
while (antw!='3')<br />
cout&lt;&lt;&quot;\n&quot;;<br />
getch();<br />
for (antw='3')<br />
exit(3);<br />
}</p>
<p>}<br />
// Ende Menü</p>
<p>void manuellezahleneingabe()<br />
{<br />
float *arrZahlen, t;<br />
bool weiter;<br />
int j, z=0, iStart, i, iDist, iNumbers ; //Zählvariable z für Auswertung Laufzeitverhalten</p>
<p>cout &lt;&lt;&quot;SHELLSORT SORTIERALGORITHMUS&quot;;</p>
<p>cout &lt;&lt; &quot;\n\nBitte Anzahl der Zahlen eingeben: &quot;;<br />
cin &gt;&gt; iNumbers;</p>
<p>arrZahlen = new float[iNumbers]; // Dynamisches Array anlegen</p>
<p>for(int i=0;i&lt;iNumbers;i++)<br />
{<br />
cout &lt;&lt; &quot;\nBitte &quot; &lt;&lt; (i+1) &lt;&lt; &quot;. Zahl eingeben: &quot;;<br />
cin &gt;&gt; arrZahlen[i];<br />
}<br />
cout &lt;&lt; &quot;\nBitte Start-Inkrement-Wert eingeben: &quot;;<br />
cin &gt;&gt; iStart;</p>
<p>do{<br />
cout &lt;&lt; &quot;\nBitte Inkrement-Distanz eingeben: &quot;;<br />
cin &gt;&gt; iDist;<br />
}<br />
while((iStart-1)%iDist!=0); // Damit bei iStart-x*iDist mind einmal 1 rauskommt</p>
<p>// Start ShellSort<br />
for(int h=iStart;h&gt;0;h=h-iDist) // Schrittweiten<br />
{<br />
//cout &lt;&lt; &quot;\n\n\n h: &quot; &lt;&lt; h;</p>
<p>for(i=h; i&lt;iNumbers; i++)<br />
{<br />
j = i;<br />
t = arrZahlen[i]; //<br />
weiter = true;</p>
<p>/*<br />
cout &lt;&lt; &quot;\nt: &quot; &lt;&lt; t &lt;&lt; &quot; i: &quot; &lt;&lt; i &lt;&lt; &quot; j: &quot; &lt;&lt; j; //Zwischenauswertung für Testphase</p>
<p>for(int x=0;x&lt;iNumbers;x++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[x];<br />
}<br />
*/</p>
<p>while(weiter &amp;&amp; (arrZahlen[j-h]&gt;t)) // Vertauschung, wenn Vorgängerzahlen größer als Nachfolger<br />
{<br />
arrZahlen[j] = arrZahlen[j-h];<br />
j -= h;<br />
weiter = (j&gt;=h);<br />
z++;<br />
}<br />
arrZahlen[j] = t; // Pivotelement an neuen Platz (kleineren Platz) schreiben</p>
<p>/* //Zwischenauswertung für Testphase<br />
cout &lt;&lt; &quot;\n&quot;;</p>
<p>for(int x=0;x&lt;iNumbers;x++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[x];<br />
}</p>
<p>cout &lt;&lt; &quot;\n\n\n&quot;;<br />
*/<br />
}<br />
}</p>
<p>cout &lt;&lt; &quot;\nAusgabe: &quot;;<br />
for(i=0;i&lt;iNumbers;i++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[i]; //Ausgabe der sortierten Zahlen</p>
<p>}<br />
cout &lt;&lt;&quot;\nNotwendige Sortierschritte: &quot; &lt;&lt;z; //Auswertung der benötigten Sortiervorgänge</p>
<p>cin &gt;&gt; i;</p>
<p>//speichern????<br />
}</p>
<p>void dateilesen()<br />
float *arrZahlen, t;<br />
bool weiter;<br />
int j, z=0, iStart, i, iDist, iNumbers ; //Zählvariable z für Auswertung Laufzeitverhalten<br />
using namespace std;</p>
<p>cout &lt;&lt;&quot;SHELLSORT SORTIERALGORITHMUS&quot;;<br />
{<br />
ifstream datei( &quot;zahlendatei.txt&quot;, ios::in );<br />
string speicher;<br />
while (datei;<br />
{<br />
//getline( &quot;zahlendatei&quot;, speicher );</p>
<p>cout &lt;&lt; speicher;}</p>
<p>cin &gt;&gt; speicher;</p>
<p>arrZahlen = new float[iNumbers]; // Dynamisches Array anlegen</p>
<p>for(int i=0;i&lt;iNumbers;i++)</p>
<p>{</p>
<p>cout &lt;&lt; &quot;\nBitte Start-Inkrement-Wert eingeben: &quot;;<br />
cin &gt;&gt; iStart;</p>
<p>do{<br />
cout &lt;&lt; &quot;\nBitte Inkrement-Distanz eingeben: &quot;;<br />
cin &gt;&gt; iDist;<br />
}<br />
while((iStart-1)%iDist!=0); // Damit bei iStart-x*iDist mind einmal 1 rauskommt</p>
<p>// Start ShellSort<br />
for(int h=iStart;h&gt;0;h=h-iDist) // Schrittweiten<br />
{<br />
//cout &lt;&lt; &quot;\n\n\n h: &quot; &lt;&lt; h;</p>
<p>for(i=h; i&lt;iNumbers; i++)<br />
{<br />
j = i;<br />
t = arrZahlen[i]; //<br />
weiter = true;</p>
<p>/*<br />
cout &lt;&lt; &quot;\nt: &quot; &lt;&lt; t &lt;&lt; &quot; i: &quot; &lt;&lt; i &lt;&lt; &quot; j: &quot; &lt;&lt; j; //Zwischenauswertung für Testphase</p>
<p>for(int x=0;x&lt;iNumbers;x++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[x];<br />
}<br />
*/</p>
<p>while(weiter &amp;&amp; (arrZahlen[j-h]&gt;t)) // Vertauschung, wenn Vorgängerzahlen größer als Nachfolger<br />
{<br />
arrZahlen[j] = arrZahlen[j-h];<br />
j -= h;<br />
weiter = (j&gt;=h);<br />
z++;<br />
}<br />
arrZahlen[j] = t; // Pivotelement an neuen Platz (kleineren Platz) schreiben</p>
<p>/* //Zwischenauswertung für Testphase<br />
cout &lt;&lt; &quot;\n&quot;;</p>
<p>for(int x=0;x&lt;iNumbers;x++)<br />
{<br />
cout &lt;&lt; &quot;\n&quot; &lt;&lt; arrZahlen[x];<br />
}</p>
<p>cout &lt;&lt; &quot;\n\n\n&quot;;<br />
*/<br />
}<br />
}</p>
<p>cout &lt;&lt;&quot;\nNotwendige Sortierschritte: &quot; &lt;&lt;z; //Auswertung der benötigten Sortiervorgänge</p>
<p>// Schreiben der sorteirten Datei in sortzahlen.txt</p>
<p>ofstream datei;<br />
datei open(&quot;sortzahlen.txt&quot;, ios::out);<br />
datei &lt;&lt; &quot;schleife für sortierte Zahlen, die irgendwo vorliegen&quot; &lt;&lt; endl;<br />
datei.close();</p>
<p>//speichern????<br />
}<br />
}</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1091245</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1091245</guid><dc:creator><![CDATA[c++ idiot]]></dc:creator><pubDate>Tue, 04 Jul 2006 13:31:26 GMT</pubDate></item><item><title><![CDATA[Reply to Die fehlenden Verbindungen der Variablen mit Algorithmus? on Tue, 04 Jul 2006 14:26:48 GMT]]></title><description><![CDATA[<p>Wie stehen denn die Zahlen in der Datei drin? Also sind Leerzeichen dahinter, oder eine Zahl pro Zeile, oder wie sonst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1091278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1091278</guid><dc:creator><![CDATA[Tobias W]]></dc:creator><pubDate>Tue, 04 Jul 2006 14:26:48 GMT</pubDate></item><item><title><![CDATA[Reply to Die fehlenden Verbindungen der Variablen mit Algorithmus? on Tue, 04 Jul 2006 14:41:46 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;iterator&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;

using namespace std;

template &lt;class T&gt;
struct out_ {
  void operator()(T v) { cout &lt;&lt; v &lt;&lt; endl; }
};

int main()
{
  /**
   * Werte einlesen
   */

  ifstream fs(&quot;datei&quot;);
  istream_iterator&lt;int&gt; ii(fs), eos;

  vector&lt;int&gt; v;
  copy(ii, eos, back_inserter(v));

  /**
   * Ausgabe
   */
  for_each(v.begin(), v.end(), out_&lt;int&gt;());
}
</code></pre>
<p>Äquivalent dazu wird mit ofstream und ostream_iterator in die Datei geschrieben. Eine Suchmachine sollte weitere Infos ausspucken <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1091284</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1091284</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Tue, 04 Jul 2006 14:41:46 GMT</pubDate></item></channel></rss>