<?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[Fehler im Algotithmus]]></title><description><![CDATA[<p>Hallo,</p>
<p>kann mir wer sagen, was an diesem Algorithmus falsch ist?<br />
Er soll Daten einlesen und sie nach der Priorität ordnen.<br />
Wenn als erstes die Priorität 2 gewählt wurde, werden zwischen dem Kopf und dem Knoten mit Priorität 2, Platzhalter eingefügt.</p>
<p>An Stelle 2 einfügen klappt noch, dann aber an Stelle 5 anfügen nicht mehr - er fügt diesen Knoten dann an der Stelle 6 an.<br />
Woran kann das liegen?</p>
<pre><code class="language-cpp">#include &lt;iostream.h&gt;
#include &lt;conio.h&gt;

class Kset
{
private:
        struct Knoten
        {
         int Inhalt;
         int Priority;
         Knoten *pNext;
         Knoten *pFront;
        };

        Knoten *Kopf;
        Knoten *Sentinel;

        int Anzahl;
        int x;

public:
        Kset();
        Kset(const Kset &amp; obj);
        Kset(const int *obj, const int Array);
        ~Kset();

        void insert_front(int obj);
        void insert_back(int obj);
        void insert_pos(int obj, int pri);
        void delete_front();
        void delete_back();
        void display();
        void push_array(const int *obj, const int Array);

        friend ostream &amp; operator &lt;&lt; (ostream &amp;os, Kset &amp; kl);
        friend istream &amp; operator &gt;&gt; (istream&amp; is, Kset &amp; kl);

        Kset&amp; operator = (const Kset &amp;alt);
};

#include &quot;impl.hpp&quot;
</code></pre>
<pre><code class="language-cpp">//insert_position///////////////////////////////////////////////////////////////

void Kset::insert_pos(int obj, int pri)
{
 Knoten *pNew = new Knoten;
 pNew-&gt;Inhalt = obj;
 pNew-&gt;Priority = pri;
 pNew-&gt;pNext = NULL;
 pNew-&gt;pFront = NULL;

 if(Anzahl == 0)
    {
        Knoten *pLeer = new Knoten;
        pLeer-&gt;Inhalt = -1;
        pLeer-&gt;Priority = -1;
        Kopf-&gt;pNext = pLeer;
        pLeer-&gt;pFront = Kopf;
        pLeer-&gt;pNext = Sentinel;
        Sentinel-&gt;pFront = pLeer;
        Knoten *pTemp = pLeer;

        for(;pri &gt; 1; pri--)
           {
                Knoten *pLeer1 = new Knoten;
                pLeer1-&gt;Inhalt = -1;
                pLeer1-&gt;Priority = -1;
                pLeer1-&gt;pFront = pTemp;
                pTemp-&gt;pNext = pLeer1;
                pLeer1-&gt;pNext = Sentinel;
                Sentinel-&gt;pFront = pTemp;
                pTemp = pLeer1;
           }
        pTemp-&gt;pNext = pNew;
        pNew-&gt;pFront = pTemp;
        pNew-&gt;pNext = Sentinel;
        Sentinel-&gt;pFront = pNew;
        Anzahl=1;

    }

 if(Anzahl &lt;= pri &amp;&amp; Anzahl != 0)
    {
        Knoten *pTemp = Sentinel-&gt;pFront;
        int zahlhinten = ((pri-Anzahl)-x);
        for(int z=zahlhinten; (z) &gt; 1; z--)
           {
                Knoten *pLeer = new Knoten;
                pLeer-&gt;Inhalt = -1;
                pLeer-&gt;Priority = -1;
                pTemp-&gt;pNext = pLeer;
                pLeer-&gt;pFront = pTemp;
                Sentinel-&gt;pFront = pLeer;
                pLeer-&gt;pNext = Sentinel;
                pTemp = pLeer;
                ++Anzahl;
           }
        pTemp-&gt;pNext = pNew;
        pNew-&gt;pFront = pTemp;
        pNew-&gt;pNext = Sentinel;
        Sentinel-&gt;pFront = pNew;
   }

 if(Anzahl &gt; pri &amp;&amp; Anzahl != 0)
    {
        Knoten *pTemp = Kopf-&gt;pNext;
        Knoten *pHilf = Kopf-&gt;pNext;
        Knoten *pDel = Kopf-&gt;pNext;
        for(; pri &gt; 1; pri--)
           {
                pTemp = pTemp-&gt;pNext;
           }
        pHilf = pTemp-&gt;pNext-&gt;pNext;
        pDel = pTemp-&gt;pNext;
        delete pDel;
        pTemp-&gt;pNext = pNew;
        pNew-&gt;pFront = pTemp;
        pNew-&gt;pNext = pHilf;
        pHilf-&gt;pFront = pNew;
         Anzahl++;

    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/152008/fehler-im-algotithmus</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 18:46:25 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/152008.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Jul 2006 18:15:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Fehler im Algotithmus on Sat, 01 Jul 2006 18:15:18 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>kann mir wer sagen, was an diesem Algorithmus falsch ist?<br />
Er soll Daten einlesen und sie nach der Priorität ordnen.<br />
Wenn als erstes die Priorität 2 gewählt wurde, werden zwischen dem Kopf und dem Knoten mit Priorität 2, Platzhalter eingefügt.</p>
<p>An Stelle 2 einfügen klappt noch, dann aber an Stelle 5 anfügen nicht mehr - er fügt diesen Knoten dann an der Stelle 6 an.<br />
Woran kann das liegen?</p>
<pre><code class="language-cpp">#include &lt;iostream.h&gt;
#include &lt;conio.h&gt;

class Kset
{
private:
        struct Knoten
        {
         int Inhalt;
         int Priority;
         Knoten *pNext;
         Knoten *pFront;
        };

        Knoten *Kopf;
        Knoten *Sentinel;

        int Anzahl;
        int x;

public:
        Kset();
        Kset(const Kset &amp; obj);
        Kset(const int *obj, const int Array);
        ~Kset();

        void insert_front(int obj);
        void insert_back(int obj);
        void insert_pos(int obj, int pri);
        void delete_front();
        void delete_back();
        void display();
        void push_array(const int *obj, const int Array);

        friend ostream &amp; operator &lt;&lt; (ostream &amp;os, Kset &amp; kl);
        friend istream &amp; operator &gt;&gt; (istream&amp; is, Kset &amp; kl);

        Kset&amp; operator = (const Kset &amp;alt);
};

#include &quot;impl.hpp&quot;
</code></pre>
<pre><code class="language-cpp">//insert_position///////////////////////////////////////////////////////////////

void Kset::insert_pos(int obj, int pri)
{
 Knoten *pNew = new Knoten;
 pNew-&gt;Inhalt = obj;
 pNew-&gt;Priority = pri;
 pNew-&gt;pNext = NULL;
 pNew-&gt;pFront = NULL;

 if(Anzahl == 0)
    {
        Knoten *pLeer = new Knoten;
        pLeer-&gt;Inhalt = -1;
        pLeer-&gt;Priority = -1;
        Kopf-&gt;pNext = pLeer;
        pLeer-&gt;pFront = Kopf;
        pLeer-&gt;pNext = Sentinel;
        Sentinel-&gt;pFront = pLeer;
        Knoten *pTemp = pLeer;

        for(;pri &gt; 1; pri--)
           {
                Knoten *pLeer1 = new Knoten;
                pLeer1-&gt;Inhalt = -1;
                pLeer1-&gt;Priority = -1;
                pLeer1-&gt;pFront = pTemp;
                pTemp-&gt;pNext = pLeer1;
                pLeer1-&gt;pNext = Sentinel;
                Sentinel-&gt;pFront = pTemp;
                pTemp = pLeer1;
           }
        pTemp-&gt;pNext = pNew;
        pNew-&gt;pFront = pTemp;
        pNew-&gt;pNext = Sentinel;
        Sentinel-&gt;pFront = pNew;
        Anzahl=1;

    }

 if(Anzahl &lt;= pri &amp;&amp; Anzahl != 0)
    {
        Knoten *pTemp = Sentinel-&gt;pFront;
        int zahlhinten = ((pri-Anzahl)-x);
        for(int z=zahlhinten; (z) &gt; 1; z--)
           {
                Knoten *pLeer = new Knoten;
                pLeer-&gt;Inhalt = -1;
                pLeer-&gt;Priority = -1;
                pTemp-&gt;pNext = pLeer;
                pLeer-&gt;pFront = pTemp;
                Sentinel-&gt;pFront = pLeer;
                pLeer-&gt;pNext = Sentinel;
                pTemp = pLeer;
                ++Anzahl;
           }
        pTemp-&gt;pNext = pNew;
        pNew-&gt;pFront = pTemp;
        pNew-&gt;pNext = Sentinel;
        Sentinel-&gt;pFront = pNew;
   }

 if(Anzahl &gt; pri &amp;&amp; Anzahl != 0)
    {
        Knoten *pTemp = Kopf-&gt;pNext;
        Knoten *pHilf = Kopf-&gt;pNext;
        Knoten *pDel = Kopf-&gt;pNext;
        for(; pri &gt; 1; pri--)
           {
                pTemp = pTemp-&gt;pNext;
           }
        pHilf = pTemp-&gt;pNext-&gt;pNext;
        pDel = pTemp-&gt;pNext;
        delete pDel;
        pTemp-&gt;pNext = pNew;
        pNew-&gt;pFront = pTemp;
        pNew-&gt;pNext = pHilf;
        pHilf-&gt;pFront = pNew;
         Anzahl++;

    }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1089725</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1089725</guid><dc:creator><![CDATA[Mr. Blonde]]></dc:creator><pubDate>Sat, 01 Jul 2006 18:15:18 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Algotithmus on Sat, 01 Jul 2006 20:24:00 GMT]]></title><description><![CDATA[<p>ich hab mir jetzt nicht alles genau angeschaut... allerdings solltest du 'else if' verwenden, da beim Einfügen den ersten Elements die ersten <strong>beiden</strong> Bedingungen erfüllt sind:<br />
du setzt nämlich im ersten Rumpf Anzahl auf 1 und prio wird bis auf 1 runtergezählt, also ist die zweite Bedingung auch erfüllt.. Genau das verhinderst du, indm du 'else if' verwendest</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1089793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1089793</guid><dc:creator><![CDATA[Dommel]]></dc:creator><pubDate>Sat, 01 Jul 2006 20:24:00 GMT</pubDate></item><item><title><![CDATA[Reply to Fehler im Algotithmus on Sat, 01 Jul 2006 21:18:41 GMT]]></title><description><![CDATA[<p>okay - ist erledigt ... das Problem besteht aber leider noch weiterhin <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1089826</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1089826</guid><dc:creator><![CDATA[Mr. Blonde]]></dc:creator><pubDate>Sat, 01 Jul 2006 21:18:41 GMT</pubDate></item></channel></rss>