{"id":3737,"date":"2021-08-10T04:03:45","date_gmt":"2021-08-10T04:03:45","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=3737"},"modified":"2022-11-18T07:22:19","modified_gmt":"2022-11-18T07:22:19","slug":"print-nodes-of-linked-list-at-given-indexes","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/","title":{"rendered":"Print Nodes Of Linked List At Given indexes"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png\" alt=\"\" \/><\/p>\n<p>This article will discuss how to print nodes of linked list at given indexes. Printing nodes of linked lists is a must to know task if you are practicing linked list. Having knowledge on data structures will definitely help for clearing the interview in the tech companies. Now let\u2019s move to our topic of how to print nodes of linked list at given indexes.<\/p>\n<\/p>\n<h3>Problem Statement<\/h3>\n<p>Given two singly linked lists l1 and l2. l2 is a singly linked list containing various indices in sorted order. We need to print the data in l1 at indices mentioned in l2. (indices are 1 based).<\/p>\n<p><strong>Input<\/strong><br \/>\nl1: <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Print-Nodes-Of-Linked-List-At-Given-indexes-input-01.png\" alt=\"\" \/><\/p>\n<p>l2: <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Print-Nodes-Of-Linked-List-At-Given-indexes_input_2-01.png\" alt=\"\" \/><\/p>\n<p><strong>Output<\/strong><br \/>\n5 10 1<\/p>\n<h3>Problem Statement Understanding How to Print Nodes of Linked List At The Given Indexes<\/h3>\n<p>Let\u2019s understand this problem with the above example. We have 5 -&gt; 18 -&gt; 9 -&gt; 10 -&gt; 1 -&gt; 73 -&gt; 11 as l1 the given linked list and 1 -&gt; 4 -&gt; 5 as l2 the linked list containing the indices to print. <\/p>\n<p>Lets mark the indices of the nodes of a given linked list l1.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Print-Nodes-Of-Linked-List-At-Given-indexes-01.png\" alt=\"\" \/><\/p>\n<p>Now let\u2019s look at the required list of indices and find the corresponding nodes.<br \/>\nThe given list of indices l2 is: 1 -&gt; 4 -&gt; 5<br \/>\nNode at index 1 = 5<br \/>\nNode at index 4 = 10<br \/>\nNode at index 5 = 1<\/p>\n<p>So we print 5 10 1 as the output.<\/p>\n<h3>Approach To Print Nodes of Linked List At The Given Indexes<\/h3>\n<p>I hope you got a basic idea of what we need to do to solve this problem. The idea is simple, since the linked list containing indices (l2) is sorted, we just need to iterate through the linked list containing values (l1) while keeping track of the current index and the index to print. Whenever the current index and index to print match, we print the value at that index and update the index to print with the next node in the linked list l2, and move to the next node in l2.<\/p>\n<p>Since it is clear what we need to do, take some time and think about how we are going to do it.<\/p>\n<h3>Algorithm To Print Nodes of Linked List At The Given Indexes<\/h3>\n<ul>\n<li>Declare 2 variables <strong>curr_indx<\/strong> and <strong>indx_to_print<\/strong> and initialize them as curr_indx = 1 and indx_to_print = l2-&gt;val i.e. the first index to print.<\/li>\n<li>Now iterate through the linked list l1 till we reach the end of either of the linked list.<\/li>\n<li>In each iteration compare the value of curr_indx with indx_to_print. If they match<\/li>\n<li>Print the value of the current node in l1.<\/li>\n<li>Move to the next node in l2<\/li>\n<li>If there are more nodes in l2 (i.e. l2!=NULL), then update the value in indx_to_print with the value in l2.<\/li>\n<li>Increment the curr_indx by 1.<\/li>\n<\/ul>\n<h3>Dry Run To Print Nodes of Linked List At The Given Indexes<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Print-Nodes-Of-Linked-List-At-Given-indexes-dry-run-01.png\" alt=\"\" \/><\/p>\n<h3>Implementation<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_3729 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_3729 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_3729 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_3729 .wpsm_nav-tabs > li.active > a, #tab_container_3729 .wpsm_nav-tabs > li.active > a:hover, #tab_container_3729 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_3729 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_3729 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_3729 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_3729 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_3729 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_3729 .wpsm_nav-tabs > li > a:hover , #tab_container_3729 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_3729 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_3729 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_3729 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_3729 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_3729 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_3729 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_3729 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3729 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_3729 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_3729 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_3729 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_3729\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_3729\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3729_1\" aria-controls=\"tabs_desc_3729_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3729_2\" aria-controls=\"tabs_desc_3729_2\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3729_3\" aria-controls=\"tabs_desc_3729_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_3729_4\" aria-controls=\"tabs_desc_3729_4\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_3729\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_3729_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n\r\n#include&lt;stdio.h&gt;\r\n#include&lt;stdlib.h&gt;\r\n\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\n \r\n\/* Function to insert a node at the beginning *\/\r\nvoid push(struct Node** head_ref, int new_data)\r\n{\r\n    struct Node *new_node = (struct Node *) malloc(sizeof(struct Node));\r\n \r\n    new_node-&gt;data = new_data;\r\n    new_node-&gt;next = (*head_ref);\r\n    (*head_ref) = new_node;\r\n}\r\n \r\n\/\/ Function to print the second list according\r\n\/\/ to the positions referred by the 1st list\r\nvoid printSecondList(struct Node* l1,struct Node* l2)\r\n{\r\n    struct Node* temp = l1;\r\n    struct Node* temp1 = l2;\r\n \r\n    \/\/ While first linked list is not null.\r\n    while (temp != NULL) {\r\n        int i = 1;\r\n \r\n        \/\/ While second linked list is not equal\r\n        \/\/ to the data in the node of the\r\n        \/\/ first linked list.\r\n        while (i &lt; temp-&gt;data) {\r\n            \/\/ Keep incrementing second list\r\n            temp1 = temp1-&gt;next;\r\n            i++;\r\n        }\r\n \r\n        \/\/ Print the node at position in second list\r\n        \/\/ pointed by current element of first list\r\n        printf(&quot;%d &quot;,temp1-&gt;data);\r\n \r\n        \/\/ Increment first linked list\r\n        temp = temp-&gt;next;\r\n \r\n        \/\/ Set temp1 to the start of the\r\n        \/\/ second linked list\r\n        temp1 = l2;\r\n    }\r\n}\r\n \r\n\/\/ Driver Code\r\nint main()\r\n{\r\n    struct Node *l1 = NULL, *l2 = NULL;\r\n \r\n    \/\/ Creating 1st list\r\n    \/\/ 2 -&gt; 5\r\n    push(&amp;l1, 5);\r\n    push(&amp;l1, 2);\r\n \r\n    \/\/ Creating 2nd list\r\n    \/\/ 4 -&gt; 5 -&gt; 6 -&gt; 7 -&gt; 8\r\n    push(&amp;l2, 8);\r\n    push(&amp;l2, 7);\r\n    push(&amp;l2, 6);\r\n    push(&amp;l2, 5);\r\n    push(&amp;l2, 4);\r\n \r\n    printSecondList(l1, l2);\r\n \r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3729_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n\r\n#include<bits\/stdc++.h>\r\nusing namespace std;\r\n\r\nstruct Node {\r\n    int val;\r\n    Node* next;\r\n\r\n    Node(int value){\r\n        val = value;\r\n        next = NULL;\r\n    }\r\n};\r\n\r\nvoid push_front(Node** head, int new_val){\r\n    Node* new_node = new Node(new_val);\r\n    new_node->next = *head;\r\n    *head = new_node;\r\n}\r\n\r\nvoid printAtIndices(Node* l1, Node* l2){\r\n    int curr_index = 1;\r\n    int indx_to_print = l2->val;\r\n\r\n    while(l1!=NULL && l2!=NULL){\r\n        if(curr_index == indx_to_print){\r\n            cout<<l1->val<<\" \";\r\n            l2 = l2->next;\r\n            \r\n            if(l2!=NULL) indx_to_print = l2->val;\r\n        }\r\n        l1 = l1->next;\r\n        curr_index ++;\r\n    }\r\n}\r\n\r\nint main(){\r\n    Node* l1 = NULL;\r\n    push_front(&l1, 11);\r\n    push_front(&l1, 73);\r\n    push_front(&l1, 1);\r\n    push_front(&l1, 10);\r\n    push_front(&l1, 9);\r\n    push_front(&l1, 18);\r\n    push_front(&l1, 5);\r\n    \/\/ 5 18 9 10 1 73 11\r\n    \r\n    Node* l2 = NULL;\r\n    push_front(&l2, 5);\r\n    push_front(&l2, 4);\r\n    push_front(&l2, 1);\r\n    \/\/ 1 4 5\r\n\r\n    printAtIndices(l1,l2);\r\n    \/\/ 5 10 1\r\n    return 0;\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3729_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass Indexes\r\n{\r\n    static class Node\r\n    {\r\n\t    int data;\r\n\t    Node next;\r\n    };\r\n    static Node push( Node head_ref, int new_data)\r\n    {\r\n\t    Node new_node = new Node();\r\n\r\n\t    new_node.data = new_data;\r\n\t    new_node.next = (head_ref);\r\n\t    (head_ref) = new_node;\r\n\t    return head_ref;\r\n    }\r\n    \/\/ Function to print the second list according\r\n    \/\/ to the positions referred by the 1st list\r\n    static void printSecondList(Node l1, Node l2)\r\n    {\r\n\t    Node temp = l1;\r\n\t    Node temp1 = l2;\r\n\r\n\t    \/\/ While first linked list is not null.\r\n\t    while (temp != null)\r\n\t    {\r\n\t\t    int i = 1;\r\n\t\t    \/\/ While second linked list is not equal\r\n\t\t    \/\/ to the data in the node of the\r\n\t\t    \/\/ first linked list.\r\n\t\t    while (i &lt; temp.data)\r\n\t\t    {\r\n\t\t\t    \/\/ Keep incrementing second list\r\n\t\t\t    temp1 = temp1.next;\r\n\t\t\t    i++;\r\n\t\t    }\r\n\t\t    \/\/ Print the node at position in second list\r\n\t\t    \/\/ pointed by current element of first list\r\n\t\t    System.out.print( temp1.data + &quot; &quot;);\r\n\r\n\t\t    \/\/ Increment first linked list\r\n\t\t    temp = temp.next;\r\n\r\n\t\t    \/\/ Set temp1 to the start of the\r\n\t\t    \/\/ second linked list\r\n\t\t    temp1 = l2;\r\n\t    }\r\n    }\r\n    \/\/ Driver Code\r\n    public static void main(String args[])\r\n    {\r\n\t    Node l1 = null, l2 = null;\r\n\r\n\t    l1 = push(l1, 5);\r\n\t    l1 = push(l1, 2);\r\n\r\n\t    l2 = push(l2, 8);\r\n\t    l2 = push(l2, 7);\r\n\t    l2 = push(l2, 6);\r\n\t    l2 = push(l2, 5);\r\n\t    l2 = push(l2, 4);\r\n\r\n\t    printSecondList(l1, l2);\r\n    }\r\n}\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_3729_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"Python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass new_Node:\r\n\t\t\r\n\tdef __init__(self, data):\r\n\t\tself.data = data\r\n\t\tself.next = None\r\n\r\ndef push(head_ref, new_data):\r\n\tnew_node = new_Node(new_data)\r\n\tnew_node.next = head_ref\r\n\thead_ref = new_node\r\n\treturn head_ref\r\n\t\r\ndef printSecondList(l1,l2):\r\n\t\r\n\tcurr_index = 1\r\n\tindex_to_print = l2.data\r\n\r\n\twhile l1 and l2:\r\n\t\tif curr_index == index_to_print:\r\n\t\t\tprint(l1.data, end=&quot; &quot;)\r\n\t\t\tl2 = l2.next\r\n\r\n\t\t\tif l2:\r\n\t\t\t\tindex_to_print = l2.data\r\n\t\tl1 = l1.next\r\n\t\tcurr_index +=1\r\n\r\nl1 = None\r\nl2 = None\r\n\r\nl1 = push(l1, 11)\r\nl1 = push(l1, 73)\r\nl1 = push(l1, 1)\r\nl1 = push(l1, 10)\r\nl1 = push(l1, 9)\r\nl1 = push(l1, 18)\r\nl1 = push(l1, 5)\r\n\r\nl2 = push(l2, 5)\r\nl2 = push(l2, 4)\r\nl2 = push(l2, 1)\r\n\r\nprintSecondList(l1, l2)\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_3729 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_3729 a\"),jQuery(\"#tab-content_3729\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h4>Output<\/h4>\n<p>5 10 1<\/p>\n<p><strong>Time complexity To Print Nodes of Linked List At The Given Indexes:<\/strong> O(n), where n is the length of the linked list.<br \/>\n<strong>Space complexity To Print Nodes of Linked List At The Given Indexes:<\/strong> O(1), as we aren\u2019t using any extra space.<\/p>\n<p>Through this article, we learned how to print nodes of a linked list at the given indices. Problems like these are good for strengthening your concepts in LinkedList. Having skills like Data Structures always help in clearning the Technical Interviews for the Giant Firms. I would highly recommend you to practice more such problems from <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a>.<\/p>\n<table width=\"641\">\n<tbody>\n<tr>\n<td colspan=\"2\" width=\"641\" style=\"text-align: center\"><strong>Related Articles<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/doubly-circular-linked-list-introduction-and-insertion\/\">Doubly circular linked list in data structure<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantages-disadvantages-and-uses-of-a-doubly-linked-list\/\">Application of doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/applications-of-linked-list-data-structure\/\">Applications of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/difference-between-a-singly-linked-list-and-a-doubly-linked-list\/\">Singly linked list vs doubly linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/advantage-and-disadvantage-of-linked-list-over-array\/\">Advantages and disadvantages of linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/menu-driven-program-for-all-operations-on-doubly-linked-list-in-c\/\">Doubly linked list all operations in C<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/binary-search\/binary-search-on-linked-list\/\">Binary search in linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/bubble-sort-for-linked-list-by-swapping-nodes\/\">Bubble sort linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-in-doubly-linked-list\/\">Deletion in doubly linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-middle-of-linked-list\/\">Delete the middle node of a linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/adding-two-polynomials-using-linked-list\/\">Polynomial addition using linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-smallest-and-largest-elements-in-a-singly-linked-list\/\">Find max value and min value in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/insert-a-node-at-a-specific-position-in-a-linked-list\/\">Insert a node at a specific position in a linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/swap-nodes-in-a-linked-list-without-swapping-data\/\">Swap nodes in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/add-two-numbers-represented-by-linked-lists-set-1\/\">Add two numbers represented by linked lists<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/find-the-first-node-of-the-loop-in-a-linked-list\/\">Find starting point of loop in linked list<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/merge-sort-on-a-singly-linked-list\/\">Merge sort linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/delete-a-node-at-a-given-position\/\">Delete a node from linked list at a given position<\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/linked-list\/remove-duplicates-from-an-unsorted-linked-list\/\">Remove duplicates from unsorted linked list<\/a><\/td>\n<td width=\"321\"><a href=\"https:\/\/prepbytes.com\/blog\/python\/python-program-to-reverse-a-linked-list\/\">Reverse a linked list in Python<\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>FAQ Related to Print Nodes Of Linked List At Given Indexes<\/h2>\n<p><ol><strong><\/p>\n<li>What&#8217;s the head of a linked list?<\/li>\n<p><\/strong><br \/>\nThe entry point into a linked list is called the head of the list. It should be noted that head is not a separate node, but the reference to the first node. If the list is empty then the head is a null reference. A linked list is a dynamic data structure.<br \/>\n<strong><\/p>\n<li>What are nodes in the linked list?<\/li>\n<p><\/strong><br \/>\nA node is a collection of two sub-elements or parts. A data part that stores the element and a next part that stores the link to the next node. A linked list is formed when many such nodes are linked together to form a chain. Each node points to the next node present in the order.<br \/>\n<strong><\/p>\n<li>What is the pointer in the linked list?<\/li>\n<p><\/strong><br \/>\nThe pointer variable that points to the first node which is named head.<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This article will discuss how to print nodes of linked list at given indexes. Printing nodes of linked lists is a must to know task if you are practicing linked list. Having knowledge on data structures will definitely help for clearing the interview in the tech companies. Now let\u2019s move to our topic of how [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-3737","post","type-post","status-publish","format-standard","hentry","category-linked-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Learn to Print Nodes Of Linked List At Given indexes<\/title>\n<meta name=\"description\" content=\"Learn to print nodes of a linked list at given indices. This blog explains how to print the nodes of a linked list at given indices.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn to Print Nodes Of Linked List At Given indexes\" \/>\n<meta property=\"og:description\" content=\"Learn to print nodes of a linked list at given indices. This blog explains how to print the nodes of a linked list at given indices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-10T04:03:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-18T07:22:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png\" \/>\n<meta name=\"author\" content=\"Prepbytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prepbytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Print Nodes Of Linked List At Given indexes\",\"datePublished\":\"2021-08-10T04:03:45+00:00\",\"dateModified\":\"2022-11-18T07:22:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/\"},\"wordCount\":876,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/\",\"name\":\"Learn to Print Nodes Of Linked List At Given indexes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png\",\"datePublished\":\"2021-08-10T04:03:45+00:00\",\"dateModified\":\"2022-11-18T07:22:19+00:00\",\"description\":\"Learn to print nodes of a linked list at given indices. This blog explains how to print the nodes of a linked list at given indices.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linked list articles\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/linked-list\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Print Nodes Of Linked List At Given indexes\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn to Print Nodes Of Linked List At Given indexes","description":"Learn to print nodes of a linked list at given indices. This blog explains how to print the nodes of a linked list at given indices.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/","og_locale":"en_US","og_type":"article","og_title":"Learn to Print Nodes Of Linked List At Given indexes","og_description":"Learn to print nodes of a linked list at given indices. This blog explains how to print the nodes of a linked list at given indices.","og_url":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-08-10T04:03:45+00:00","article_modified_time":"2022-11-18T07:22:19+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Print Nodes Of Linked List At Given indexes","datePublished":"2021-08-10T04:03:45+00:00","dateModified":"2022-11-18T07:22:19+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/"},"wordCount":876,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/","url":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/","name":"Learn to Print Nodes Of Linked List At Given indexes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png","datePublished":"2021-08-10T04:03:45+00:00","dateModified":"2022-11-18T07:22:19+00:00","description":"Learn to print nodes of a linked list at given indices. This blog explains how to print the nodes of a linked list at given indices.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644922208742-90.Print-nodes_Artboard%203.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/print-nodes-of-linked-list-at-given-indexes\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Linked list articles","item":"https:\/\/prepbytes.com\/blog\/category\/linked-list\/"},{"@type":"ListItem","position":3,"name":"Print Nodes Of Linked List At Given indexes"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=3737"}],"version-history":[{"count":7,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3737\/revisions"}],"predecessor-version":[{"id":10582,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/3737\/revisions\/10582"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=3737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=3737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=3737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}