<?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[Listen]]></title><description><![CDATA[<p>Hi ich hab hier eine kleine Aufgabe über einfache Listen und hab noch nicht wirklich viel Ahnung von C++, auf jedenfall stehe ich gerade etwas auf dem Schlauch</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;List.h&quot;

int size = 0;

int List::getSize(){
	return size;
}

	int List::getElementAt(int index){
	if((index &lt;= size) &amp;&amp; (index &gt; 0) &amp;&amp; (size &gt;= 1)){
		while ( index &gt; 0 ){
		LE* nextFirstLE = first-&gt;next;
		delete first;
		first = nextFirstLE;
		}
		return first;
	}
}

List::List() {
	first = 0;
	last  = 0;
}

List::~List() {
	while (first != 0)
		removeFirst();
}

void List::append(int value) {

	LE* newLE = new LE(value, 0);

	if (first == 0) {
		first = newLE;
		size++;
	}

	else
		last-&gt;next = newLE;
		size++;

	last = newLE;
}

void List::removeFirst() {

	if (first != 0) {

		LE* nextFirstLE = first-&gt;next;

		delete first;
		size--;

		first = nextFirstLE;

		if (first == 0)
			last = 0;
	}
}
</code></pre>
<p>Ich bin gerad dabei die getElementAt Methode zu schreiben, dummerweise weiß ich nicht ganz wie ich das Objekt richtig zurückgeben kann da anscheinend der Zeiger first nicht ganz reicht da es rot markiert wird, falls mir jemand helfen kann ich bitte drum, vielen dank <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>
]]></description><link>https://www.c-plusplus.net/forum/topic/302122/listen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 17:18:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/302122.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Apr 2012 16:52:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Listen on Wed, 11 Apr 2012 16:52:45 GMT]]></title><description><![CDATA[<p>Hi ich hab hier eine kleine Aufgabe über einfache Listen und hab noch nicht wirklich viel Ahnung von C++, auf jedenfall stehe ich gerade etwas auf dem Schlauch</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;List.h&quot;

int size = 0;

int List::getSize(){
	return size;
}

	int List::getElementAt(int index){
	if((index &lt;= size) &amp;&amp; (index &gt; 0) &amp;&amp; (size &gt;= 1)){
		while ( index &gt; 0 ){
		LE* nextFirstLE = first-&gt;next;
		delete first;
		first = nextFirstLE;
		}
		return first;
	}
}

List::List() {
	first = 0;
	last  = 0;
}

List::~List() {
	while (first != 0)
		removeFirst();
}

void List::append(int value) {

	LE* newLE = new LE(value, 0);

	if (first == 0) {
		first = newLE;
		size++;
	}

	else
		last-&gt;next = newLE;
		size++;

	last = newLE;
}

void List::removeFirst() {

	if (first != 0) {

		LE* nextFirstLE = first-&gt;next;

		delete first;
		size--;

		first = nextFirstLE;

		if (first == 0)
			last = 0;
	}
}
</code></pre>
<p>Ich bin gerad dabei die getElementAt Methode zu schreiben, dummerweise weiß ich nicht ganz wie ich das Objekt richtig zurückgeben kann da anscheinend der Zeiger first nicht ganz reicht da es rot markiert wird, falls mir jemand helfen kann ich bitte drum, vielen dank <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2200873</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2200873</guid><dc:creator><![CDATA[Lenard1]]></dc:creator><pubDate>Wed, 11 Apr 2012 16:52:45 GMT</pubDate></item><item><title><![CDATA[Reply to Listen on Wed, 11 Apr 2012 16:54:26 GMT]]></title><description><![CDATA[<p>bei getElementAt fehlt natürlich noch ein size--</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2200875</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2200875</guid><dc:creator><![CDATA[Lenard1]]></dc:creator><pubDate>Wed, 11 Apr 2012 16:54:26 GMT</pubDate></item><item><title><![CDATA[Reply to Listen on Wed, 11 Apr 2012 16:55:13 GMT]]></title><description><![CDATA[<p>index-- herrgot <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>
]]></description><link>https://www.c-plusplus.net/forum/post/2200876</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2200876</guid><dc:creator><![CDATA[Lenard1]]></dc:creator><pubDate>Wed, 11 Apr 2012 16:55:13 GMT</pubDate></item><item><title><![CDATA[Reply to Listen on Wed, 11 Apr 2012 17:40:30 GMT]]></title><description><![CDATA[<p>Was soll denn getElementAt überhaupt machen? Denn das, was dein code da macht wäre sicher nicht, was ich von einem getElementAt erwarten würde. Du löscht da &quot;nebenbei&quot; scheinbar deine ganze Liste bis zum entsprechendem Index. Anders gesagt: Was zum Teufel macht das &quot;delete&quot; da?</p>
<p>Zu deiner eigentlichen Frage, ich vermute mal du hast eine Liste von ints, dann müsste man noch wissen was &quot;LE&quot; überhaupt ist, aber ich vermute mal ein Knoten. Dann wird die Antwort wohl sowas wie first-&gt;value oder so sein? Ohne mir noch mehr Gedanken gemacht zu haben, Kristallkugel bedienen ist schwierig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2200889</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2200889</guid><dc:creator><![CDATA[kleiner Troll]]></dc:creator><pubDate>Wed, 11 Apr 2012 17:40:30 GMT</pubDate></item></channel></rss>