<?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[Insertion Sort mit Binärer Suche]]></title><description><![CDATA[<p>Hi Experten,</p>
<p>kann mir evtl. jemand dabei helfen, den insertion sort mit binärer Suche zu implementieren:</p>
<p>Mein insertionsort sieht so aus:</p>
<pre><code>int main(int argc, char** argv) {
    const int max =10;
    int n=0, zahl; //n ist Schrittzähler
    int A[max]={0};

    do{
        cout &lt;&lt; &quot;Bitte eine Zahl eingeben: &quot;;
        cin &gt;&gt; zahl;
        A[n] = zahl; //Schreibt zahl an n-te stelle des Arrays
        if (zahl !=0) n++;
    }while (zahl !=0 &amp;&amp; n&lt;max);

    for (int i=1;i&lt;n; i++) { //durchläufe
        int tmp =A[i]; //schreibt den Wert von i-ter Stelle in tmp
        int j = i-1;

        while (j&gt;0 &amp;&amp; tmp&lt;A[j]) { //verschieben Größerer Elemente
            A[j+1] = A[j];
            j--;
        }
        A[j+1] =tmp; //Einfügen an die Richtige Stelle

    }
    for ( int i = 0; i &lt; n ; i++) //Ausgeben
        cout &lt;&lt; A[i] &lt;&lt; &quot; &quot;;
    cout &lt;&lt; endl;

    return 0;
}
</code></pre>
<pre><code>int key, pos;
int left, right, mid;
bool found = false;
cout &lt;&lt; &quot;Suche nach: &quot;;
cin &gt;&gt; key;
left = 0;
right = n - 1;
while (left &lt;= right) {
    mid = (left + right) / 2; //Median bestimmen
    if (key &lt; A[mid]) right = mid - 1;
    else if (key &gt; A[mid]) left = mid + 1;
    else { // gefunden
        found = true;
        pos = mid;
        break;
    }
}
if (!found)
    cout &lt;&lt; &quot;Element nicht vorhanden!!&quot;
        &lt;&lt; endl;
else
    cout &lt;&lt; &quot;Element liegt an Stelle &quot; &lt;&lt; pos &lt;&lt; endl;
</code></pre>
<p>Danke euch schon mal für eure Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/321969/insertion-sort-mit-binärer-suche</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Jul 2026 20:30:00 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/321969.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 01 Dec 2013 14:51:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Insertion Sort mit Binärer Suche on Sun, 01 Dec 2013 14:53:42 GMT]]></title><description><![CDATA[<p>Hi Experten,</p>
<p>kann mir evtl. jemand dabei helfen, den insertion sort mit binärer Suche zu implementieren:</p>
<p>Mein insertionsort sieht so aus:</p>
<pre><code>int main(int argc, char** argv) {
    const int max =10;
    int n=0, zahl; //n ist Schrittzähler
    int A[max]={0};

    do{
        cout &lt;&lt; &quot;Bitte eine Zahl eingeben: &quot;;
        cin &gt;&gt; zahl;
        A[n] = zahl; //Schreibt zahl an n-te stelle des Arrays
        if (zahl !=0) n++;
    }while (zahl !=0 &amp;&amp; n&lt;max);

    for (int i=1;i&lt;n; i++) { //durchläufe
        int tmp =A[i]; //schreibt den Wert von i-ter Stelle in tmp
        int j = i-1;

        while (j&gt;0 &amp;&amp; tmp&lt;A[j]) { //verschieben Größerer Elemente
            A[j+1] = A[j];
            j--;
        }
        A[j+1] =tmp; //Einfügen an die Richtige Stelle

    }
    for ( int i = 0; i &lt; n ; i++) //Ausgeben
        cout &lt;&lt; A[i] &lt;&lt; &quot; &quot;;
    cout &lt;&lt; endl;

    return 0;
}
</code></pre>
<pre><code>int key, pos;
int left, right, mid;
bool found = false;
cout &lt;&lt; &quot;Suche nach: &quot;;
cin &gt;&gt; key;
left = 0;
right = n - 1;
while (left &lt;= right) {
    mid = (left + right) / 2; //Median bestimmen
    if (key &lt; A[mid]) right = mid - 1;
    else if (key &gt; A[mid]) left = mid + 1;
    else { // gefunden
        found = true;
        pos = mid;
        break;
    }
}
if (!found)
    cout &lt;&lt; &quot;Element nicht vorhanden!!&quot;
        &lt;&lt; endl;
else
    cout &lt;&lt; &quot;Element liegt an Stelle &quot; &lt;&lt; pos &lt;&lt; endl;
</code></pre>
<p>Danke euch schon mal für eure Hilfe</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369214</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369214</guid><dc:creator><![CDATA[schrödinger]]></dc:creator><pubDate>Sun, 01 Dec 2013 14:53:42 GMT</pubDate></item><item><title><![CDATA[Reply to Insertion Sort mit Binärer Suche on Sun, 01 Dec 2013 16:09:10 GMT]]></title><description><![CDATA[<p>Nein</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369228</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369228</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Sun, 01 Dec 2013 16:09:10 GMT</pubDate></item><item><title><![CDATA[Reply to Insertion Sort mit Binärer Suche on Sun, 01 Dec 2013 19:34:15 GMT]]></title><description><![CDATA[<p>Hä, ich sehe das Problem nicht, du hast die Sachen doch schon? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2369264</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2369264</guid><dc:creator><![CDATA[hardware]]></dc:creator><pubDate>Sun, 01 Dec 2013 19:34:15 GMT</pubDate></item></channel></rss>