<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>linked list | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/linked-list/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Mon, 23 Nov 2020 09:03:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>linked list | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>New C tutorial on implementing linked lists with pointers</title>
		<link>https://learncgames.com/c-tutorial-on-implementing-linked-lists-with-pointers/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=c-tutorial-on-implementing-linked-lists-with-pointers</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 23 Nov 2020 00:00:04 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[pointers]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[linked list]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1870</guid>

					<description><![CDATA[<p>Once you leave the relative safety of arrays and structs, the linked list using pointers is probably the next thing to consider.  Technically it&#8217;s a liked list of structs containing pointers. It&#8217;s like an array of structs only instead of allocating contiguous memory for an array, you allocate memory for each struct as you need [&#8230;]</p>
The post <a href="https://learncgames.com/c-tutorial-on-implementing-linked-lists-with-pointers/">New C tutorial on implementing linked lists with pointers</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:357,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/manuchi-1728328\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2462428&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:358,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2462428&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_1872" aria-describedby="caption-attachment-1872" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-1872" src="https://learncgames.com/wp-content/uploads/2020/11/background-2462428_640-300x300.jpg" alt="Links" width="300" height="300" srcset="https://learncgames.com/wp-content/uploads/2020/11/background-2462428_640-300x300.jpg 300w, https://learncgames.com/wp-content/uploads/2020/11/background-2462428_640-150x150.jpg 150w, https://learncgames.com/wp-content/uploads/2020/11/background-2462428_640.jpg 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-1872" class="wp-caption-text">Image by <a href="https://pixabay.com/users/manuchi-1728328/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2462428">Денис Марчук</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=2462428">Pixabay</a></figcaption></figure>
<p>Once you leave the relative safety of arrays and structs, the linked list using pointers is probably the next thing to consider.  Technically it&#8217;s a liked list of structs containing pointers. It&#8217;s like an array of structs only instead of allocating contiguous memory for an array, you allocate memory for each struct as you need it.</p>
<p>Linked lists are easy to program. You have a head pointer (<em>a pointer to the head of the list</em>). It starts as null as the list is empty. There&#8217;s two types of linked lists (single and double). A single list has a pointer to the next node (or is 0 at the end of the list) and can only be processed from head to end. A node is just a fancy name for the struct in the linked list.</p>
<p>A double list has two pointers. One to the previous node and one to the next. As well as a head pointer you need a tail pointer and you can process the list from head to tail or tail to head (i.e. backwards).</p>
<p>Now the first operation you can do on a linked list is add a node to it.</p>
<p>To do this you</p>
<ol>
<li>Allocate memory for the node using malloc.</li>
<li> Copy the head pointer to the node&#8217;s <strong>next</strong> pointer.</li>
<li>Stitch the node in by pointing the <strong>head pointer</strong> to this node.</li>
</ol>
<p>So when you are building a list you add each node to the head, in a sense pushing it in front of the others.</p>
<p>Double linked lists have to do an additional operation which is set the next node&#8217;s previous pointer to point to the newly added pointer. And when you add the first node to a double linked list, you have to set the tail pointer to point to this first node. After that it never changes unless you have an Append node at the end.</p>
<h3>Uses of Linked Lists</h3>
<p>Anything that needs dynamic memory for example a text editor might use a double linked list to store all the text. Each line could be a different length. So each node would not only have a pointer to the next and previous nodes, it would have a pointer to the text in memory. When you insert a new line, you are just inserting a new node in the list at the current node that the cursor is on.</p>
<p>Or you might store a directed graph (<em>a bit like in the picture</em>) where each node has multiple pointers to other nodes.  Anyway I&#8217;ve published <a title="Link to tutorial eight on pointers and linked lists" href="https://learncgames.com/tutorial-eight-about-pointer-variables/" target="_blank" rel="nofollow noopener noreferrer">tutorial eight</a> which looks at pointers and linked lists.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/c-tutorial-on-implementing-linked-lists-with-pointers/">New C tutorial on implementing linked lists with pointers</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1870</post-id>	</item>
	</channel>
</rss>
