<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bibek Khanal</title>
    <description>The latest articles on DEV Community by Bibek Khanal (@bibek_khanal_863076fe9ec4).</description>
    <link>https://dev.to/bibek_khanal_863076fe9ec4</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3196604%2F1f5bc111-bf88-4004-b573-b473ad0c6527.jpg</url>
      <title>DEV Community: Bibek Khanal</title>
      <link>https://dev.to/bibek_khanal_863076fe9ec4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bibek_khanal_863076fe9ec4"/>
    <language>en</language>
    <item>
      <title>Unraveling the Chain: A Deep Dive into Linked Lists 🔗</title>
      <dc:creator>Bibek Khanal</dc:creator>
      <pubDate>Fri, 23 May 2025 17:47:21 +0000</pubDate>
      <link>https://dev.to/bibek_khanal_863076fe9ec4/unraveling-the-chain-a-deep-dive-into-linked-lists-22n6</link>
      <guid>https://dev.to/bibek_khanal_863076fe9ec4/unraveling-the-chain-a-deep-dive-into-linked-lists-22n6</guid>
      <description>&lt;h2&gt;
  
  
  Understanding Linked Lists in Computer Science
&lt;/h2&gt;

&lt;p&gt;Linked lists are a fundamental data structure in computer science, forming the backbone of many complex systems and algorithms. Understanding them is crucial for any aspiring programmer or software engineer. This article will explore the different types of linked lists, their uses, historical significance, advantages, drawbacks, and why they remain incredibly relevant today.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Exactly is a Linked List?
&lt;/h2&gt;

&lt;p&gt;At its core, a linked list is a linear collection of data elements, called &lt;strong&gt;nodes&lt;/strong&gt;. Unlike arrays, where elements are stored in contiguous memory locations, linked list nodes can be scattered anywhere in memory. Each node contains two key pieces of information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data&lt;/strong&gt;: The actual value stored in the node (e.g., a number, a string, or a more complex object).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pointer (or Link)&lt;/strong&gt;: A reference to the next node in the sequence. The last node typically points to &lt;code&gt;null&lt;/code&gt; (or &lt;code&gt;None&lt;/code&gt;), indicating the end of the list.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Think of it like a treasure hunt 🗺️: each clue (node) tells you where to find the next one, until you reach the final treasure (the end of the list).&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Types of Linked Lists
&lt;/h2&gt;

&lt;p&gt;There are several variations of linked lists, each with its own characteristics and use cases:&lt;/p&gt;

&lt;h3&gt;
  
  
  Singly Linked List
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structure&lt;/strong&gt;: Each node has one pointer, pointing to the next node in the list. Traversal is unidirectional (forward only).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplicity&lt;/strong&gt;: It’s the simplest form of a linked list.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Doubly Linked List
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structure&lt;/strong&gt;: Each node has two pointers: one to the next node and one to the previous node.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bidirectional Traversal&lt;/strong&gt;: Allows for traversing the list both forwards and backwards, making operations like deletion more efficient as you don’t need to keep track of the previous node separately.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Circular Linked List
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structure&lt;/strong&gt;: The last node’s &lt;code&gt;next&lt;/code&gt; pointer points back to the first node instead of &lt;code&gt;null&lt;/code&gt;, forming a circle.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use Case&lt;/strong&gt;: Useful for applications that require a continuous cycle, like a round-robin scheduler or managing a playlist that repeats. This can be implemented for both singly and doubly linked lists.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Doubly Circular Linked List
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structure&lt;/strong&gt;: Combines the features of a doubly linked list and a circular linked list. The last node’s “next” pointer points to the first node, and the first node’s “previous” pointer points to the last node.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexible Traversal&lt;/strong&gt;: Allows traversal in either direction, continuously.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Are Linked Lists Important? 🤔
&lt;/h2&gt;

&lt;p&gt;Linked lists are a cornerstone of computer science education and practice for several reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Memory Allocation&lt;/strong&gt;: They can grow or shrink in size during program execution, unlike arrays which typically have a fixed size. This makes them ideal for situations where the amount of data is unknown beforehand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient Insertions and Deletions&lt;/strong&gt;: Adding or removing elements in the middle of a linked list is generally more efficient than in an array. For arrays, these operations often require shifting many elements. In a linked list, you only need to update a few pointers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Foundation for Other Data Structures&lt;/strong&gt;: Many more complex data structures, such as stacks, queues, hash tables (for collision resolution), and graphs, can be implemented using linked lists.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Understanding Pointers and Memory Management&lt;/strong&gt;: Working with linked lists provides a solid understanding of how pointers and dynamic memory allocation work, which is crucial for low-level programming and system design.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Historical Significance 📜
&lt;/h2&gt;

&lt;p&gt;The concept of linked lists was developed in the mid-1950s by Allen Newell, Cliff Shaw, and Herbert A. Simon at RAND Corporation while working on their Information Processing Language (IPL). IPL was one of the earliest programming languages and heavily utilized linked lists to manage its memory and data structures. This made linked lists one of the earliest dynamic data storage techniques. Their work laid the groundwork for many concepts in artificial intelligence and list processing languages like LISP.&lt;/p&gt;




&lt;h2&gt;
  
  
  Uses in Complex Systems and Algorithms ⚙️
&lt;/h2&gt;

&lt;p&gt;Linked lists are not just academic concepts; they are actively used in various real-world applications and sophisticated algorithms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Operating Systems&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory Management: To keep track of free and allocated memory blocks.&lt;/li&gt;
&lt;li&gt;File System Management: Directory structures can sometimes be represented using linked lists or tree-like structures based on them.&lt;/li&gt;
&lt;li&gt;Process Management: Task schedulers often use linked lists (like circular queues) to manage processes waiting for CPU time.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Web Browsers&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The “back” and “forward” navigation buttons often use a doubly linked list to store the history of visited pages.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Compilers and Interpreters&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symbol tables, which store information about identifiers (variables, functions, etc.), can be implemented using hash tables that employ linked lists for collision chaining.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Computer Graphics&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To manage objects in a scene or vertices in a polygon mesh.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Other Data Structures&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stacks and Queues: Can be efficiently implemented using linked lists.&lt;/li&gt;
&lt;li&gt;Graphs (Adjacency Lists): Used to represent sparse graphs, where each node (vertex) has a linked list of its neighbors.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Algorithms&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Polynomial Representation: Representing polynomials where each node stores a coefficient and an exponent.&lt;/li&gt;
&lt;li&gt;Radix Sort: Uses linked lists to group elements.&lt;/li&gt;
&lt;li&gt;Big Number Arithmetic: Handling numbers larger than what standard data types can hold.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Advantages of Linked Lists Over Arrays 👍
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Size&lt;/strong&gt;: As mentioned, they can easily grow and shrink. Arrays are static in size or require costly resizing operations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ease of Insertion/Deletion&lt;/strong&gt;: Inserting or deleting elements in the middle of a linked list is generally O(1) (constant time) if you have a pointer to the node before the insertion/deletion point. For arrays, it’s O(n) (linear time) due to the need to shift elements.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory Efficiency (in some cases)&lt;/strong&gt;: While nodes in a linked list have an overhead for storing pointers, linked lists can be more memory efficient if the list is sparse or the maximum size is unknown, avoiding overallocation of memory that might occur with arrays.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Wasted Memory (Contiguity not required)&lt;/strong&gt;: Since nodes are not stored contiguously, there’s no large chunk of memory that needs to be pre-allocated and potentially left unused.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Drawbacks of Linked Lists 👎
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Memory Overhead&lt;/strong&gt;: Each node in a linked list requires extra memory to store the pointer(s). For small data items, this overhead can be significant.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Random Access&lt;/strong&gt;: Elements in a linked list must be accessed sequentially starting from the first node. You cannot directly access the i-th element in O(1) time as you can with an array. Accessing an element takes O(n) time in the worst case.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache Performance&lt;/strong&gt;: Because linked list nodes can be scattered in memory, they can lead to poor cache locality. Arrays, being contiguous, often benefit from better cache performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reverse Traversal (for Singly Linked Lists)&lt;/strong&gt;: Traversing a singly linked list in reverse is cumbersome and typically requires recursion or an auxiliary stack, adding complexity or space. Doubly linked lists solve this but at the cost of an extra pointer per node.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Should YOU Know About Linked Lists? 🧑‍💻
&lt;/h2&gt;

&lt;p&gt;Understanding linked lists is fundamental for several reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Problem-Solving Skills&lt;/strong&gt;: They teach you to think about data relationships and memory management at a lower level.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Technical Interviews&lt;/strong&gt;: Questions about linked lists are very common in software engineering interviews as they test a candidate’s understanding of basic data structures, algorithms, and pointer manipulation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Foundation for Advanced Concepts&lt;/strong&gt;: They are the foundation for more advanced data structures and algorithms. Knowing them well will make learning these more complex topics easier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient System Design&lt;/strong&gt;:  A grasp of linked lists helps in making informed decisions about which data structure is most appropriate for a given problem, leading to more efficient and scalable system designs.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Python Implementation: Doubly Circular Linked List 🧑‍💻
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__str__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;NodeHandler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;_isempty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;checking if the list is empty or not&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__len__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Returns the node count of the list&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt; Appends the node to the end of the list &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;newnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_isempty&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
      &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
      &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
      &lt;span class="n"&gt;newnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
      &lt;span class="n"&gt;newnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
      &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
      &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;appended data - &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;

    &lt;span class="n"&gt;newnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;
    &lt;span class="n"&gt;newnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;appended data - &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;prepend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Prepends the node to the end of the list&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;newnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;_isempty&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
      &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
      &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
      &lt;span class="n"&gt;newnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
      &lt;span class="n"&gt;newnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
      &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
      &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prepended data - &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt;

    &lt;span class="n"&gt;newnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;
    &lt;span class="n"&gt;newnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;newnode&lt;/span&gt;
    &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prepended data - &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;traverse_forward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Traverse the list from head to tail&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;traverse_backward&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Traverse the list from tail to head&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Searches the list for a key 
    if found returns True else False&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
      &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Deletes the node with the given key from the list&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# if current is the head
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="n"&gt;nextnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
          &lt;span class="n"&gt;nextnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt;
          &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nextnode&lt;/span&gt;
          &lt;span class="nf"&gt;del&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

        &lt;span class="c1"&gt;# if current is the tail
&lt;/span&gt;        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="n"&gt;prevnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;
          &lt;span class="n"&gt;prevnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;
          &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prevnode&lt;/span&gt;
          &lt;span class="nf"&gt;del&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="n"&gt;prevnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt;
          &lt;span class="n"&gt;nextnode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
          &lt;span class="n"&gt;prevnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nextnode&lt;/span&gt;
          &lt;span class="n"&gt;nextnode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prev&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prevnode&lt;/span&gt;
          &lt;span class="nf"&gt;del&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;key &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; deleted!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt;
      &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;key &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; not found!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;

&lt;span class="n"&gt;nodehandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;NodeHandler&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#output:
#appended data - 1
#appended data - 2
#appended data - 3
&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;prepend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;#output:
#prepended data - 0
#prepended data - -1
#prepended data - -2
&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;traverse_forward&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;#output:
#-2 
#-1 
#0 
#1 
#2 
#3
&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;traverse_backward&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;#output:
#3 
#2 
#1 
#0 
#-1 
#-2
&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#output:
#True
&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;nodehandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;traverse_forward&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;#output:
#key -2 deleted!
#-1
#0
#1
#2
#3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Linked lists, in their various forms, are a versatile and powerful data structure. While they have their drawbacks, their strengths in dynamic memory management and efficient insertion/deletion operations make them indispensable in a programmer’s toolkit. From the early days of computing to modern complex systems, linked lists continue to play a vital role, underscoring their enduring importance in the world of computer science. Mastering them is a significant step towards becoming a more proficient and knowledgeable software developer.&lt;/p&gt;

</description>
      <category>dsa</category>
      <category>computerscience</category>
      <category>programming</category>
    </item>
    <item>
      <title>Unmasking Linux: What Building From Scratch Truly Reveals 🐧</title>
      <dc:creator>Bibek Khanal</dc:creator>
      <pubDate>Thu, 22 May 2025 16:47:35 +0000</pubDate>
      <link>https://dev.to/bibek_khanal_863076fe9ec4/unmasking-linux-what-building-from-scratch-truly-reveals-4l9c</link>
      <guid>https://dev.to/bibek_khanal_863076fe9ec4/unmasking-linux-what-building-from-scratch-truly-reveals-4l9c</guid>
      <description>&lt;h2&gt;
  
  
  What Exactly Is Linux From Scratch 🤔?
&lt;/h2&gt;

&lt;p&gt;Ever wondered what truly lies beneath the polished surface of your Linux distribution? Beyond the package managers and desktop environments, a complex symphony of software works in harmony to bring your operating system to life. For those brave souls eager to conduct this orchestra themselves, there’s a legendary tome: &lt;strong&gt;Linux From Scratch (LFS)&lt;/strong&gt;. This isn’t just a book; it’s a journey into the very heart of Linux—a challenging yet immensely rewarding endeavor to build your own custom Linux system, piece by piece, directly from its source code.&lt;/p&gt;

&lt;p&gt;Linux From Scratch is, at its core, an educational project that provides highly detailed, step-by-step instructions for building a complete, functional Linux system from the ground up. Authored by Gerard Beekmans and now maintained by a dedicated community, the LFS book guides you through partitioning your disk, compiling a cross-compiler toolchain, building essential libraries and utilities, and finally, compiling the Linux kernel itself.&lt;/p&gt;

&lt;p&gt;The end result isn’t another pre-packaged distribution like Ubuntu or Fedora. Instead, you birth a minimalist, bespoke Linux installation containing only what you explicitly choose to include. Think of it as the ultimate DIY project for the aspiring Linux guru.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Embark on Such a Quest? The Uses and Rewards 🎁
&lt;/h2&gt;

&lt;p&gt;So, why would anyone voluntarily subject themselves to such a demanding task? The motivations are as varied as the individuals who undertake it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unparalleled Understanding&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This is the primary draw. LFS demystifies the Linux operating system. You’ll learn what each core package does, why it’s needed, and how it interacts with others. You’ll grasp the boot process, kernel configuration, and the role of critical libraries like Glibc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ultimate Customization and Control&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Most Linux distros come bundled with a plethora of unwanted and unused software packages. With LFS, your system will be exactly what you want it to be — lean, optimized, and free of any bloat. You decide every package, every feature.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Problem-Solving Skills&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
You &lt;em&gt;will&lt;/em&gt; encounter issues. Debugging them improves your troubleshooting abilities in a way that using pre-built distributions rarely does.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A Foundation for Deeper Exploration&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
LFS is often a stepping stone. Once you’ve built a base system, the &lt;em&gt;Beyond Linux From Scratch&lt;/em&gt; (BLFS) book guides you in adding X Window System, desktop environments, networking tools, and much more. There are even offshoots like &lt;em&gt;Cross Linux From Scratch&lt;/em&gt; (CLFS) for embedded systems.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Street Cred&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Let’s be honest, successfully building an LFS system earns you significant bragging rights in Linux circles.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Lessons Forged in the Compiler Fires: What You Will Learn 🔥
&lt;/h2&gt;

&lt;p&gt;The educational value of LFS cannot be overstated. You’ll gain practical experience and deep knowledge in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Linux Boot Process&lt;/strong&gt;: From the bootloader (GRUB) to init or systemd.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kernel Compilation&lt;/strong&gt;: Configuring, compiling, and installing the Linux kernel tailored to your hardware.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Toolchain&lt;/strong&gt;: Understanding the roles of GCC (compiler), Binutils (assembler, linker), and Glibc (C library).
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Package Management (Conceptually)&lt;/strong&gt;: While LFS doesn’t initially include a package manager, the manual compilation process helps you appreciate package management systems.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Filesystem Hierarchy&lt;/strong&gt;: A clearer understanding of what goes where and why.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shell Scripting&lt;/strong&gt;: Frequent command-line interaction naturally improves your scripting abilities.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Resolution&lt;/strong&gt;: You'll see firsthand how packages depend on each other.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;System Configuration&lt;/strong&gt;: Editing critical system files for networking, services, and startup.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Navigating the Path: Interesting Aspects and Words of Caution ⚠️
&lt;/h2&gt;

&lt;p&gt;The LFS journey is filled with unique experiences and potential pitfalls:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The “Chroot” Environment&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
One of the most fascinating parts is creating a &lt;code&gt;chroot&lt;/code&gt; (change root) environment. This isolates your new LFS system from your host system, allowing you to build within it as if it were already the primary OS.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Version Vigilance&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The LFS book specifies &lt;em&gt;exact&lt;/em&gt; versions for each package. Deviating from these, especially as a beginner, can lead to a cascade of compatibility issues. Stick to the script!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Tedium and the Thrill&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Hours can be spent watching compilation messages scroll by. Yet, the thrill of each successful package build and, ultimately, booting the system, is immense.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Host System Integrity&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Always ensure your host Linux system is stable and backed up. You’ll be installing tools and making changes that, if done carelessly, could affect it.&lt;br&gt;&lt;br&gt;
&lt;em&gt;(Ask me how I know… let’s just say my host kernel had a “bad day” once.)&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Read, Re-read, and Understand&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Don’t just blindly copy-paste commands. The LFS book often explains &lt;em&gt;why&lt;/em&gt; a command is being run. Understanding this enhances the learning experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Patience is Your Superpower&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Rushing leads to mistakes. When you hit a wall, step away, clear your head, and then tackle the problem methodically. The LFS community (forums, mailing lists) is also a valuable resource if you’re truly stuck.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Gearing Up: Requirements for the Build 🛠️
&lt;/h2&gt;

&lt;p&gt;Before you dive in, ensure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A Working Host Linux System&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Any existing Linux distribution (e.g., Debian, Fedora, Arch, openSUSE) will do.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Essential Software on the Host&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A C compiler (GCC), Binutils, Bash, Coreutils, and other basic development tools. The LFS book’s preface lists all prerequisites.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A Dedicated Partition&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A blank partition of sufficient size (LFS recommends at least 10 GB for the base system; more if building BLFS).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Internet Connection&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
To download the source code for all the packages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sufficient Hardware&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A reasonably modern CPU and adequate RAM will significantly speed up compilation. LFS &lt;em&gt;can&lt;/em&gt; be built on older hardware, but it will take much longer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Familiarity with the Command Line&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
You should be comfortable navigating the filesystem and using a terminal editor like &lt;code&gt;nano&lt;/code&gt; or &lt;code&gt;vim&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The LFS Book Itself&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Available for free from the &lt;a href="https://www.linuxfromscratch.org" rel="noopener noreferrer"&gt;Linux From Scratch website&lt;/a&gt;. Always use the latest stable version.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why LFS Matters for Your Future in Tech 🚀
&lt;/h2&gt;

&lt;p&gt;In an era of increasingly abstracted and containerized systems, the deep, fundamental knowledge gained from an LFS build is more valuable than ever.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stronger Linux Fundamentals&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This expertise is highly sought after in roles like System Administrator, DevOps Engineer, Cloud Engineer, and Embedded Systems Developer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Superior Troubleshooting&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Understanding how the system is built from the ground up makes you a far more effective troubleshooter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Foundation for Specialization&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Whether you’re interested in kernel development, security hardening, or building custom appliances, LFS provides an unparalleled foundation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Appreciation for Abstraction&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
After an LFS build, you’ll appreciate the convenience that modern distributions and tools like Docker provide — while also understanding their underlying mechanisms.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A Mindset of Mastery&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Completing LFS instills confidence and a problem-solving mindset transferable to any complex technical challenge.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Embarking on the Linux From Scratch journey is a commitment, but the dividends it pays in knowledge, skill, and understanding are immeasurable. It’s a rite of passage for those who truly want to master the Linux environment — transforming you from a mere user into a veritable architect of your own operating system.&lt;/p&gt;

&lt;p&gt;So, download the book, clear your schedule, and prepare for one of the most challenging and enlightening adventures the world of open source has to offer.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;Pro Tip&lt;/strong&gt;: While the Linux From Scratch book is meticulously detailed, some learners find visual demonstrations incredibly helpful. If you’re looking for video walkthroughs to supplement your LFS journey, &lt;a href="https://www.youtube.com/playlist?list=PLyc5xVO2uDsB9d49xOfLDObv9O0a0G6kH" rel="noopener noreferrer"&gt;this playlist from Kernotex&lt;/a&gt; might be quite helpful.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Good luck, and happy building!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>lfs</category>
    </item>
  </channel>
</rss>
