<?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[Singly linked list linear search Algorithmus -&amp;gt; equivalent?]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich schaue mir gerade unsere Programmier-Folien für die Vorlesung an. Folgendes ist gegeben:</p>
<pre><code>NodePtr search(NodePtr head, int target)
{
    NodePtr here = head;

    if (here == NULL)
    {
        return NULL;
    }
    else
    {
        while (here-&gt;data != target &amp;&amp; here-&gt;link != NULL)
        {
            here = here-&gt;link;
        }
        if (here-&gt;data == target)
        {
            return here;
        }
        else
        {
            return NULL;
        }
    }
}
</code></pre>
<p>Ich meine, wenn schon C in C++, dann aber so:</p>
<pre><code>NodePtr search(NodePtr head, int target)
{
    for ( ; head; head = head-&gt;link)
    {
        if (head-&gt;data == target)
        {
            return head;
        }
    }
    return nullptr;
}
</code></pre>
<p>Die Lösung ist doch mindestens genau so gut, oder? Meine Argumente: Die Kopie eines Pointers nochmal kopieren ist Schwachsinn. Es wird der Sonderfall head=nullptr elegant gehandhabt. Es wird ebenfalls frühst-möglich die Suche beendet.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/340273/singly-linked-list-linear-search-algorithmus-gt-equivalent</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 08:35:59 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/340273.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Oct 2016 23:09:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Singly linked list linear search Algorithmus -&amp;gt; equivalent? on Fri, 28 Oct 2016 23:11:10 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich schaue mir gerade unsere Programmier-Folien für die Vorlesung an. Folgendes ist gegeben:</p>
<pre><code>NodePtr search(NodePtr head, int target)
{
    NodePtr here = head;

    if (here == NULL)
    {
        return NULL;
    }
    else
    {
        while (here-&gt;data != target &amp;&amp; here-&gt;link != NULL)
        {
            here = here-&gt;link;
        }
        if (here-&gt;data == target)
        {
            return here;
        }
        else
        {
            return NULL;
        }
    }
}
</code></pre>
<p>Ich meine, wenn schon C in C++, dann aber so:</p>
<pre><code>NodePtr search(NodePtr head, int target)
{
    for ( ; head; head = head-&gt;link)
    {
        if (head-&gt;data == target)
        {
            return head;
        }
    }
    return nullptr;
}
</code></pre>
<p>Die Lösung ist doch mindestens genau so gut, oder? Meine Argumente: Die Kopie eines Pointers nochmal kopieren ist Schwachsinn. Es wird der Sonderfall head=nullptr elegant gehandhabt. Es wird ebenfalls frühst-möglich die Suche beendet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2513288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2513288</guid><dc:creator><![CDATA[HarteWare]]></dc:creator><pubDate>Fri, 28 Oct 2016 23:11:10 GMT</pubDate></item><item><title><![CDATA[Reply to Singly linked list linear search Algorithmus -&amp;gt; equivalent? on Sat, 29 Oct 2016 05:41:26 GMT]]></title><description><![CDATA[<p>Du solltest den Kurs geben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2513292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2513292</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sat, 29 Oct 2016 05:41:26 GMT</pubDate></item><item><title><![CDATA[Reply to Singly linked list linear search Algorithmus -&amp;gt; equivalent? on Sat, 29 Oct 2016 11:45:29 GMT]]></title><description><![CDATA[<p>Ganz so weit würde ich nicht gehen, aber ich leite daraus mal ab, dass die Umformung gut ist.</p>
<p>LG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2513322</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2513322</guid><dc:creator><![CDATA[HarteWare]]></dc:creator><pubDate>Sat, 29 Oct 2016 11:45:29 GMT</pubDate></item><item><title><![CDATA[Reply to Singly linked list linear search Algorithmus -&amp;gt; equivalent? on Sat, 29 Oct 2016 19:26:48 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>HarteWare schrieb:</p>
<blockquote>
<p>ich schaue mir gerade unsere Programmier-Folien für die Vorlesung an. Folgendes ist gegeben:</p>
<pre><code>NodePtr search(NodePtr head, int target)
{ // ... Puh!
</code></pre>
</blockquote>
<p>Wechsle den Dozenten.</p>
<p>HarteWare schrieb:</p>
<blockquote>
<p>Ich meine, wenn schon C in C++, dann aber so:</p>
<pre><code>NodePtr search(NodePtr head, int target)
{
    for ( ; head; head = head-&gt;link)
    {
        if (head-&gt;data == target)
        {
            return head;
        }
    }
    return nullptr;
}
</code></pre>
<p>Die Lösung ist doch mindestens genau so gut, oder?</p>
</blockquote>
<p>Die Lösung ist deutlich besser.</p>
<p>Du kannst aber noch einen drauf setzen:</p>
<pre><code>NodePtr search( NodePtr head, int target )
{
    for( ; head &amp;&amp; head-&gt;data != target; head = head-&gt;link )
        ;
    return head;
}
</code></pre>
<p>Gruß<br />
Werner</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2513362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2513362</guid><dc:creator><![CDATA[Werner Salomon]]></dc:creator><pubDate>Sat, 29 Oct 2016 19:26:48 GMT</pubDate></item><item><title><![CDATA[Reply to Singly linked list linear search Algorithmus -&amp;gt; equivalent? on Sun, 30 Oct 2016 13:50:37 GMT]]></title><description><![CDATA[<p>stimmt wäre noch kürzer <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> Vielen Dank für eure Antworten!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2513455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2513455</guid><dc:creator><![CDATA[HarteWare]]></dc:creator><pubDate>Sun, 30 Oct 2016 13:50:37 GMT</pubDate></item><item><title><![CDATA[Reply to Singly linked list linear search Algorithmus -&amp;gt; equivalent? on Sun, 30 Oct 2016 13:57:41 GMT]]></title><description><![CDATA[<p>Da würde ich aber den Code eher so schreiben:</p>
<pre><code class="language-cpp">NodePtr search( NodePtr head, int target )
{
    while(head &amp;&amp; head-&gt;data != target)
        head = head-&gt;link;

    return head;
}
</code></pre>
<p>Ist m.E. lesbarer und verständlicher.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2513456</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2513456</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Sun, 30 Oct 2016 13:57:41 GMT</pubDate></item></channel></rss>