<?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[[LinkedList] Einfügen von Daten versagt zur Laufzeit]]></title><description><![CDATA[<p>Hi,<br />
ich bin's nochmal ;). Wenn die Fragerei nervt tut es mir Leid, aber ich habe<br />
echt keine Ahnung wo hier der Fehler liegen könnte!<br />
Ich habe die einfach verkette Liste nun soweit fertig, dass zumindest der<br />
Compiler Ruhe gibt und Funktionen wie &quot;getLength()&quot;, &quot;initCursor()&quot; etc (halt<br />
der Kleinkram) schon laufen. Nur schaffe ich es jetzt nicht dieses zum<br />
laufen zu bringen:<br />
Sobald ich versuche ein Objekt vom Typ Kontakt einzufügen schmiert die Anwendung<br />
mit einer Fehlermeldung (&quot;Read konnte nicht im Speicherbereich xy ausgeführt<br />
werden&quot;) ab.</p>
<p>Ich hänge hier mal den Sourcecode und die Test-Routine an, sollte das zu lang<br />
werden möge einer der Mods den Source kicken und ich schaue mal, dass ich den<br />
dann (ähnlich gut formatiert) auf irgendeiner Homepage publik mache.</p>
<p>Hier nun der Quelltext:</p>
<p>1. Der Knoten meiner Liste</p>
<pre><code class="language-cpp">Node::Node()
{
}

Node::~Node()
{
}

Node::Node(Kontakt k)
{
    content = k;
}

Node::Node(Kontakt k, Node &amp; n)
{
    content = k;
    nextNode = &amp;n;
}

Node &amp; Node::operator= (const Node &amp; rhs)
{
    content = rhs.content;
    nextNode = rhs.nextNode;
    return *this;
}

bool Node::operator == (const Node &amp; rhs)
{
    if ((content == rhs.content) &amp;&amp; (nextNode == rhs.nextNode))
        return true;
    return false;
}
</code></pre>
<p>2. Die Liste selbst:</p>
<pre><code class="language-cpp">LinkedList::LinkedList()
{
    beginning = NULL;
    cursor = NULL;
}

LinkedList::~LinkedList()
{
}

bool LinkedList::isEmpty()
{
    return beginning == NULL;
}

void LinkedList::initCursor()
{
    cursor = beginning;
}

int LinkedList::getLength()
{
    initCursor();
    int l = 0;
    while (cursor != NULL)
    {
        l++;
        cursor = cursor-&gt;nextNode;
    }
    return l;
}

bool LinkedList::isValidPosition(int position)
{
    return (position &gt;= 1) &amp;&amp; (position &lt;= getLength());
}

void LinkedList::setCursor(int position)
{
    if (isValidPosition(position))
    {
        initCursor();
        for (int i = 0; i &lt; position; i++)
            cursor = cursor-&gt;nextNode;
    }
}

void LinkedList::insertAfter(Kontakt k, int position)
{
    setCursor(position);
    if (cursor != NULL)
    {
        Node n(k, *cursor-&gt;nextNode);
        cursor-&gt;nextNode = &amp;n;
    }
}

void LinkedList::insertBefore(Kontakt k, int position)
{
    if (position &gt; 1)
        insertAfter(k, position-1);
    else
    {
        if (isEmpty())
        {
            Node n(k);
            beginning = &amp;n;
        }
        else
        {
            Node n(k, *beginning);
            beginning = &amp;n;
        }
    }
}

Kontakt LinkedList::getContent(int position)
{
    setCursor(position);
    if (cursor == NULL)
    {
        Kontakt k;
        return k;
    }
    return cursor-&gt;content;
}

void LinkedList::remove(int position)
{
    if (isValidPosition(position))
    {
        if (position == 1)
            beginning = beginning-&gt;nextNode;
        else
        {
            setCursor(position-1);
            cursor-&gt;nextNode = cursor-&gt;nextNode-&gt;nextNode;
        }
    }
}

int LinkedList::find(Kontakt k)
{
    int p = 0;
    int l = 0;
    initCursor();
    while (cursor != NULL)
    {
        l++;
        if (cursor-&gt;content == k)
        {
            p = l;
            break;
        }
        cursor = cursor-&gt;nextNode;
    }
    return p;
}

void LinkedList::add(Kontakt k)
{
    if (isEmpty())
        insertBefore(k, 1);
    else
        insertAfter(k, getLength());
}
</code></pre>
<p>Und 3. die Test-Routine (soweit bisher fertig):</p>
<pre><code class="language-cpp">void CMyAdressesDlg::OnTestbefehleListeMain() 
{
    LinkedList l;
    Kontakt k;
    k.setzeKontakt(&quot;a&quot;, &quot;b&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;);
    l.add(k);
    CString s;
    int i = l.getLength();
    s.Format(&quot;%d&quot;, i);
    i = MessageBox(s, &quot;xx&quot;);
    Kontakt a;
    // a = l.getContent(l.getLength());
}
</code></pre>
<p>Es wäre echt nett wenn der ein oder andere Kenner sich dieses mal ansehen würde<br />
und mir eventuell sogar helfen könnte.</p>
<p>Danke im Voraus,<br />
Khadgar</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/6504/linkedlist-einfügen-von-daten-versagt-zur-laufzeit</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 08:26:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/6504.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 Jul 2003 19:53:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [LinkedList] Einfügen von Daten versagt zur Laufzeit on Mon, 07 Jul 2003 19:53:00 GMT]]></title><description><![CDATA[<p>Hi,<br />
ich bin's nochmal ;). Wenn die Fragerei nervt tut es mir Leid, aber ich habe<br />
echt keine Ahnung wo hier der Fehler liegen könnte!<br />
Ich habe die einfach verkette Liste nun soweit fertig, dass zumindest der<br />
Compiler Ruhe gibt und Funktionen wie &quot;getLength()&quot;, &quot;initCursor()&quot; etc (halt<br />
der Kleinkram) schon laufen. Nur schaffe ich es jetzt nicht dieses zum<br />
laufen zu bringen:<br />
Sobald ich versuche ein Objekt vom Typ Kontakt einzufügen schmiert die Anwendung<br />
mit einer Fehlermeldung (&quot;Read konnte nicht im Speicherbereich xy ausgeführt<br />
werden&quot;) ab.</p>
<p>Ich hänge hier mal den Sourcecode und die Test-Routine an, sollte das zu lang<br />
werden möge einer der Mods den Source kicken und ich schaue mal, dass ich den<br />
dann (ähnlich gut formatiert) auf irgendeiner Homepage publik mache.</p>
<p>Hier nun der Quelltext:</p>
<p>1. Der Knoten meiner Liste</p>
<pre><code class="language-cpp">Node::Node()
{
}

Node::~Node()
{
}

Node::Node(Kontakt k)
{
    content = k;
}

Node::Node(Kontakt k, Node &amp; n)
{
    content = k;
    nextNode = &amp;n;
}

Node &amp; Node::operator= (const Node &amp; rhs)
{
    content = rhs.content;
    nextNode = rhs.nextNode;
    return *this;
}

bool Node::operator == (const Node &amp; rhs)
{
    if ((content == rhs.content) &amp;&amp; (nextNode == rhs.nextNode))
        return true;
    return false;
}
</code></pre>
<p>2. Die Liste selbst:</p>
<pre><code class="language-cpp">LinkedList::LinkedList()
{
    beginning = NULL;
    cursor = NULL;
}

LinkedList::~LinkedList()
{
}

bool LinkedList::isEmpty()
{
    return beginning == NULL;
}

void LinkedList::initCursor()
{
    cursor = beginning;
}

int LinkedList::getLength()
{
    initCursor();
    int l = 0;
    while (cursor != NULL)
    {
        l++;
        cursor = cursor-&gt;nextNode;
    }
    return l;
}

bool LinkedList::isValidPosition(int position)
{
    return (position &gt;= 1) &amp;&amp; (position &lt;= getLength());
}

void LinkedList::setCursor(int position)
{
    if (isValidPosition(position))
    {
        initCursor();
        for (int i = 0; i &lt; position; i++)
            cursor = cursor-&gt;nextNode;
    }
}

void LinkedList::insertAfter(Kontakt k, int position)
{
    setCursor(position);
    if (cursor != NULL)
    {
        Node n(k, *cursor-&gt;nextNode);
        cursor-&gt;nextNode = &amp;n;
    }
}

void LinkedList::insertBefore(Kontakt k, int position)
{
    if (position &gt; 1)
        insertAfter(k, position-1);
    else
    {
        if (isEmpty())
        {
            Node n(k);
            beginning = &amp;n;
        }
        else
        {
            Node n(k, *beginning);
            beginning = &amp;n;
        }
    }
}

Kontakt LinkedList::getContent(int position)
{
    setCursor(position);
    if (cursor == NULL)
    {
        Kontakt k;
        return k;
    }
    return cursor-&gt;content;
}

void LinkedList::remove(int position)
{
    if (isValidPosition(position))
    {
        if (position == 1)
            beginning = beginning-&gt;nextNode;
        else
        {
            setCursor(position-1);
            cursor-&gt;nextNode = cursor-&gt;nextNode-&gt;nextNode;
        }
    }
}

int LinkedList::find(Kontakt k)
{
    int p = 0;
    int l = 0;
    initCursor();
    while (cursor != NULL)
    {
        l++;
        if (cursor-&gt;content == k)
        {
            p = l;
            break;
        }
        cursor = cursor-&gt;nextNode;
    }
    return p;
}

void LinkedList::add(Kontakt k)
{
    if (isEmpty())
        insertBefore(k, 1);
    else
        insertAfter(k, getLength());
}
</code></pre>
<p>Und 3. die Test-Routine (soweit bisher fertig):</p>
<pre><code class="language-cpp">void CMyAdressesDlg::OnTestbefehleListeMain() 
{
    LinkedList l;
    Kontakt k;
    k.setzeKontakt(&quot;a&quot;, &quot;b&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;);
    l.add(k);
    CString s;
    int i = l.getLength();
    s.Format(&quot;%d&quot;, i);
    i = MessageBox(s, &quot;xx&quot;);
    Kontakt a;
    // a = l.getContent(l.getLength());
}
</code></pre>
<p>Es wäre echt nett wenn der ein oder andere Kenner sich dieses mal ansehen würde<br />
und mir eventuell sogar helfen könnte.</p>
<p>Danke im Voraus,<br />
Khadgar</p>
]]></description><link>https://www.c-plusplus.net/forum/post/31587</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/31587</guid><dc:creator><![CDATA[Khadgar]]></dc:creator><pubDate>Mon, 07 Jul 2003 19:53:00 GMT</pubDate></item><item><title><![CDATA[Reply to [LinkedList] Einfügen von Daten versagt zur Laufzeit on Tue, 08 Jul 2003 03:56:00 GMT]]></title><description><![CDATA[<p>2 Dinge, die mir auffallen:</p>
<p>1. Im Konstruktor von Node solltest du immer nextNode initialisieren, das fehlt in einigen Versionen</p>
<p>2. in insertAfter bzw. insertBefore:<br />
Node n(k);<br />
beginning = &amp;n;<br />
Die Variable n wird nach Ende der Funktion zerstört, beginning zeigt dann bestenfalls auf Speichermüll!<br />
Du musst Node dynamisch anlegen:<br />
beginning = new Node(k);<br />
Du musst also generell mit Zeigern arbeiten, Referenzen sind hier wenig geeignet.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/31588</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/31588</guid><dc:creator><![CDATA[tag]]></dc:creator><pubDate>Tue, 08 Jul 2003 03:56:00 GMT</pubDate></item><item><title><![CDATA[Reply to [LinkedList] Einfügen von Daten versagt zur Laufzeit on Tue, 08 Jul 2003 09:28:00 GMT]]></title><description><![CDATA[<p>Hi tag,<br />
Danke, dass du dich des Problems angenommen hast!<br />
Die Liste läuft dank dir endlich (fast) so wie es sein sollte und ich denke<br />
den Rest kann ich nun auch hinbiegen <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="🙂"
    /></p>
<p>Danke,<br />
Khadgar</p>
]]></description><link>https://www.c-plusplus.net/forum/post/31589</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/31589</guid><dc:creator><![CDATA[Khadgar]]></dc:creator><pubDate>Tue, 08 Jul 2003 09:28:00 GMT</pubDate></item></channel></rss>