<?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[Doubly linked list - elemente kopieren]]></title><description><![CDATA[<p>Also, für die Uni sollen wir ne Linked List bauen. Die wird Teil eines größeren Projekts. aber irgendwie haut das bei mir nicht ganz hin.</p>
<p>In meinem Test hierfür habe ich eine LinkedList von Streams gehabt.</p>
<p>Ich kann Sachen hinzufügen, aber bei der get funktion crasht das programm(...Access violation reading location...) und der debugger(MS-VS2005) verweist mich auf zeile 85 in &quot;ios&quot;. Wenn ich schritt für schritt durch den code gehe passiert das beim nach dem Zurückgeben des Stream objekts und beim benutzen des selbigen.</p>
<p>Habe mal die Benutzung der vector Klasse der STL auskommentiert, aber im Prinzip soll diese Funktionalität implementiert werden. (Gewrappt funktioniert alles)</p>
<pre><code class="language-cpp">template &lt;class T&gt; class LinkedList;

template &lt;class TYPE&gt; class ListEntry{
	friend class LinkedList&lt;TYPE&gt;;
private:
	ListEntry* next;
	TYPE* data;
	ListEntry* previous;
	ListEntry&lt;TYPE&gt;(TYPE&amp; entrydata, ListEntry* ptrPrevious, ListEntry* ptrNext){
		this-&gt;data = &amp;entrydata;
		this-&gt;next = ptrNext;
		this-&gt;previous = ptrPrevious;
	}
};

template &lt;class T&gt;
class LinkedList{
private:
	//std::vector&lt;T&gt; list;

	ListEntry&lt;T&gt;* head;
	ListEntry&lt;T&gt;* tail;
	unsigned int numEntries;
protected:
public:
	LinkedList(){
		head = NULL;
		tail = NULL;
		numEntries = 0;
	}

	~LinkedList(){
		ListEntry&lt;T&gt;* temp;
		while(NULL != head){
			temp = head;
			head = head-&gt;next;
			delete temp;
		}
	}

	void add(const T&amp; val){
		ListEntry&lt;T&gt;* newElt = new ListEntry&lt;T&gt;(T(val), tail, NULL);
		if(NULL == head){
			head = newElt;
			tail = newElt;
		}
		else{
			tail-&gt;next = newElt;
			tail = tail-&gt;next;
		}
		numEntries++;
		//list.push_back(val);
	}

	void erase(unsigned int id){

		if(id&gt;=0 &amp;&amp; id &lt; numEntries){
			ListEntry&lt;T&gt;* iterator = head;
			for(int step = 0; step&lt;id; step++){
				iterator = iterator-&gt;next;
			}
			iterator-&gt;previous-&gt;next = iterator-&gt;next;
			iterator-&gt;next-&gt;previous = iterator-&gt;previous;
			iterator-&gt;previous = NULL;
			iterator-&gt;next = NULL;
			delete iterator;
			numEntries--;
		}
		else{
			throw &quot;Index out of Bounds&quot;;
		}

		//list.erase(list.begin()+id);
	}

	bool isEmpty() const{
		//return numEntries==0;
		return list.size()&lt;=0;
	} 

	T&amp; get(int id){

		if(id&gt;=0 &amp;&amp; id &lt; numEntries){
			ListEntry&lt;T&gt;* iterator = head;
			for(int step = 0; step&lt;id; step++){
				iterator = iterator-&gt;next;
			}
			return *(iterator-&gt;data);
		}
		else{
			throw &quot;Index out of Bounds&quot;;
		}

		//return this-&gt;list[id];
	}

	const T&amp; getReadOnly(int id) const{	

		if(id&gt;=0 &amp;&amp; id &lt; numEntries){
			ListEntry&lt;T&gt;* iterator = head;
			for(int step = 0; step&lt;id; step++){
				iterator = iterator-&gt;next;
			}
			return *(iterator-&gt;data);
		}
		else{
			throw &quot;Index out of Bounds&quot;;
		}

		// return this-&gt;list[id];
	}

	size_t size(void) const{
		//return list.size();
		return numEntries;
	}
};
</code></pre>
<p>So, wäre dankbar wenn mit jemand sagen könnte was ich falsch gemacht habe.</p>
<p>Danke,<br />
CStarter</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/227413/doubly-linked-list-elemente-kopieren</link><generator>RSS for Node</generator><lastBuildDate>Wed, 30 Sep 2026 03:19:41 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/227413.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 14 Nov 2008 19:41:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Doubly linked list - elemente kopieren on Fri, 14 Nov 2008 19:41:02 GMT]]></title><description><![CDATA[<p>Also, für die Uni sollen wir ne Linked List bauen. Die wird Teil eines größeren Projekts. aber irgendwie haut das bei mir nicht ganz hin.</p>
<p>In meinem Test hierfür habe ich eine LinkedList von Streams gehabt.</p>
<p>Ich kann Sachen hinzufügen, aber bei der get funktion crasht das programm(...Access violation reading location...) und der debugger(MS-VS2005) verweist mich auf zeile 85 in &quot;ios&quot;. Wenn ich schritt für schritt durch den code gehe passiert das beim nach dem Zurückgeben des Stream objekts und beim benutzen des selbigen.</p>
<p>Habe mal die Benutzung der vector Klasse der STL auskommentiert, aber im Prinzip soll diese Funktionalität implementiert werden. (Gewrappt funktioniert alles)</p>
<pre><code class="language-cpp">template &lt;class T&gt; class LinkedList;

template &lt;class TYPE&gt; class ListEntry{
	friend class LinkedList&lt;TYPE&gt;;
private:
	ListEntry* next;
	TYPE* data;
	ListEntry* previous;
	ListEntry&lt;TYPE&gt;(TYPE&amp; entrydata, ListEntry* ptrPrevious, ListEntry* ptrNext){
		this-&gt;data = &amp;entrydata;
		this-&gt;next = ptrNext;
		this-&gt;previous = ptrPrevious;
	}
};

template &lt;class T&gt;
class LinkedList{
private:
	//std::vector&lt;T&gt; list;

	ListEntry&lt;T&gt;* head;
	ListEntry&lt;T&gt;* tail;
	unsigned int numEntries;
protected:
public:
	LinkedList(){
		head = NULL;
		tail = NULL;
		numEntries = 0;
	}

	~LinkedList(){
		ListEntry&lt;T&gt;* temp;
		while(NULL != head){
			temp = head;
			head = head-&gt;next;
			delete temp;
		}
	}

	void add(const T&amp; val){
		ListEntry&lt;T&gt;* newElt = new ListEntry&lt;T&gt;(T(val), tail, NULL);
		if(NULL == head){
			head = newElt;
			tail = newElt;
		}
		else{
			tail-&gt;next = newElt;
			tail = tail-&gt;next;
		}
		numEntries++;
		//list.push_back(val);
	}

	void erase(unsigned int id){

		if(id&gt;=0 &amp;&amp; id &lt; numEntries){
			ListEntry&lt;T&gt;* iterator = head;
			for(int step = 0; step&lt;id; step++){
				iterator = iterator-&gt;next;
			}
			iterator-&gt;previous-&gt;next = iterator-&gt;next;
			iterator-&gt;next-&gt;previous = iterator-&gt;previous;
			iterator-&gt;previous = NULL;
			iterator-&gt;next = NULL;
			delete iterator;
			numEntries--;
		}
		else{
			throw &quot;Index out of Bounds&quot;;
		}

		//list.erase(list.begin()+id);
	}

	bool isEmpty() const{
		//return numEntries==0;
		return list.size()&lt;=0;
	} 

	T&amp; get(int id){

		if(id&gt;=0 &amp;&amp; id &lt; numEntries){
			ListEntry&lt;T&gt;* iterator = head;
			for(int step = 0; step&lt;id; step++){
				iterator = iterator-&gt;next;
			}
			return *(iterator-&gt;data);
		}
		else{
			throw &quot;Index out of Bounds&quot;;
		}

		//return this-&gt;list[id];
	}

	const T&amp; getReadOnly(int id) const{	

		if(id&gt;=0 &amp;&amp; id &lt; numEntries){
			ListEntry&lt;T&gt;* iterator = head;
			for(int step = 0; step&lt;id; step++){
				iterator = iterator-&gt;next;
			}
			return *(iterator-&gt;data);
		}
		else{
			throw &quot;Index out of Bounds&quot;;
		}

		// return this-&gt;list[id];
	}

	size_t size(void) const{
		//return list.size();
		return numEntries;
	}
};
</code></pre>
<p>So, wäre dankbar wenn mit jemand sagen könnte was ich falsch gemacht habe.</p>
<p>Danke,<br />
CStarter</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1614899</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1614899</guid><dc:creator><![CDATA[CStarter]]></dc:creator><pubDate>Fri, 14 Nov 2008 19:41:02 GMT</pubDate></item><item><title><![CDATA[Reply to Doubly linked list - elemente kopieren on Fri, 14 Nov 2008 19:58:54 GMT]]></title><description><![CDATA[<p>Sache hat sich habs gerade gelöst. hab jetzt einen pointer für die neuen elemente benutzt statt ein objekt. das funktioniert dann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1614907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1614907</guid><dc:creator><![CDATA[CStarter]]></dc:creator><pubDate>Fri, 14 Nov 2008 19:58:54 GMT</pubDate></item></channel></rss>