{"id":5526,"date":"2021-10-11T07:43:02","date_gmt":"2021-10-11T07:43:02","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5526"},"modified":"2022-12-01T06:24:12","modified_gmt":"2022-12-01T06:24:12","slug":"write-a-c-function-to-print-the-middle-of-a-linked-list","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/","title":{"rendered":"Write a C function to print the middle of a linked list"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png\" alt=\"\" \/><\/p>\n<p>This blog will discuss how to make a C function to print the middle of a linked list. Linked list is one of the most interesting topics when you start practicing data structures. This blog is having both a naive and optimal approach to make a c function to print the middle of a linked list. Let\u2019s discuss how to make a C function to print the middle of a linked list<\/p>\n<h2>How To Make C Function To Print The Middle Of A Linked List<\/h2>\n<p>In this problem, we are given a linked list. We have to find the middle of the linked list.<\/p>\n<p>Let&#8217;s suppose we have a linked list whose length is <strong>L<\/strong>, then the middle of the linked list will be the <strong>(L\/2)<\/strong><sup>th<\/sup> node of the linked list.<br \/>\nSuppose the given list is 5 \u2192 10 \u2192 3 \u2192 4 \u2192 8.<\/p>\n<ul>\n<li>The length of this linked list is 5.<\/li>\n<li>So, (5\/2) = 2<sup>nd<\/sup> node will be the middle node of the linked list.<\/li>\n<li>The middle of the linked list will be the node at 2<sup>nd<\/sup> position, which is 3, considering 0 based indexing.<\/li>\n<\/ul>\n<p>Taking another example, let\u2019s assume that the given linked list 1 \u2192 3 \u2192 5 \u2192 7 \u2192 9 \u2192 11.<\/p>\n<ul>\n<li>In this case, the length of this linked list is 6. So, (6\/2) = 3<sup>rd<\/sup> node will be the middle node of the linked list.<\/li>\n<li>The middle of the linked list will be the node at 3<sup>rd<\/sup> position, which is 7, considering 0 based indexing.<\/li>\n<\/ul>\n<p>Now, I think from the above examples, the problem statement is clear. Let\u2019s see how we can approach it.<br \/>\nBefore moving to the further to approach section, try to think about how you can approach this problem.<\/p>\n<ul>\n<li>If stuck, no problem, we will thoroughly see how we can approach this problem in the next section.<\/li>\n<\/ul>\n<p>There are two solutions to this problem. One is the naive one and the second one is the optimal solution. The naive solution requires two traversals of the list, while the optimal solution only requires a single traversal of the linked list.<\/p>\n<p>Let&#8217;s have a glance at the naive approach and then see what we can do to optimize it.<\/p>\n<h2>Approach and Algorithm (Naive approach) To Make C Function To Print The Middle Of A Linked List<\/h2>\n<p>Here, in this approach, we first calculate the length of the list. Let the length be <strong>len<\/strong>.<\/p>\n<ul>\n<li>Now, we traverse till the <strong>(len\/2)<\/strong><sup>th<\/sup> node and print it as it is obviously the middle node of the list.<\/li>\n<\/ul>\n<p>This is the naive approach to solve this problem, but as we are preparing for coding interviews of big companies, we should be familiar with techniques to find the middle node of the linked list without finding the length first.<br \/>\nThe optimal solution requires a single traversal of the linked list and is the best way to find the middle of a linked list.<\/p>\n<p><strong>Time Complexity To Make C Function To Print The Middle Of A Linked List:<\/strong> O(N) &#8211; two traversals required.<\/p>\n<p><strong>Space Complexity To Make C Function To Print The Middle Of A Linked List:<\/strong> O(1), as only temporary variables are being created.<\/p>\n<p><strong>Now, let us discuss the approach in which we can find the middle of a linked list with a single traversal.<\/strong><\/p>\n<p>What if we start by taking two pointers, say <strong>slow<\/strong> and <strong>fast<\/strong>, and make both of them point to the <strong>head<\/strong> initially.<\/p>\n<ul>\n<li>Now, what will happen if we make the <strong>slow<\/strong> jump one place and the <strong>fast<\/strong> jump two places (<strong>fast moving with twice the speed of slow<\/strong>).<\/li>\n<li>If we notice carefully, by doing the above step, when the <strong>fast<\/strong> will reach the end of the list, the <strong>slow<\/strong> will be pointing to the <strong>middle<\/strong> of the list. With the help of this technique, we can reach the <strong>middle node of a linked list in a single pass<\/strong>.<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> The reason why our <strong>slow<\/strong> pointer will be pointing to the <strong>middle<\/strong> of the linked list when the <strong>fast<\/strong> pointer is at the end is that, as our <strong>slow<\/strong> pointer is travelling with half the speed of <strong>fast<\/strong> pointer so when the <strong>fast<\/strong> pointer will reach the end of the linked list, till that time <strong>slow pointer will have only travelled half the distance as travelled by fast pointer<\/strong> and hence it will be at the <strong>middle of the linked list<\/strong>.<\/p>\n<p>Do you know what the above-explained method is called?<\/p>\n<ul>\n<li>This method is called the <strong>tortoise and hare method<\/strong> or the <strong>slow and fast pointer method<\/strong>. The slow and fast pointer method has been explained in detail in the approach section and the dry run.<\/li>\n<\/ul>\n<p>Let us have a glance at the approach.<\/p>\n<h2>Approach (Optimal) To Make C Function To Print The Middle Of A Linked List<\/h2>\n<p>Let us see what the <strong>slow and fast pointer technique<\/strong> is:<\/p>\n<ul>\n<li>\n<p>Initially, both the pointers will point to the <strong>head<\/strong> of the linked list.<\/p>\n<\/li>\n<li>\n<p>Then, we will move both of the pointers.<\/p>\n<ul>\n<li>The <strong>fast pointer<\/strong> will jump <strong>two places<\/strong>, whereas the <strong>slow pointer<\/strong> will <strong>one place<\/strong>.<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>When the <strong>fast pointer<\/strong> will reach the end of the linked list, the <strong>slow pointer<\/strong> will be pointing to the <strong>middle of the linked list<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<h2>Algorithm To Make C Function To Print The Middle Of A Linked List<\/h2>\n<ul>\n<li>Create two pointers say <strong>slow<\/strong> and <strong>fast<\/strong>. Initially, point both the <strong>slow<\/strong> and the <strong>fast<\/strong> to the head of the list.<\/li>\n<li>Now, the <strong>slow<\/strong> will jump one place, and the <strong>fast<\/strong> will jump two places until the <strong>fast<\/strong> reaches the end of the list.<\/li>\n<li>When the <strong>fast pointer reaches the end<\/strong> of the list, the <strong>slow will be pointing to the middle<\/strong> of the list.<\/li>\n<li>In the end, return the data of the <strong>slow pointer<\/strong>, as the slow will be pointing to the middle of the list.<\/li>\n<\/ul>\n<h3>Dry Run To Make C Function To Print The Middle Of A Linked List<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/10\/p_1-5.png\" alt=\"\" \/><\/p>\n<h2>Code Implementation To Make C Function To Print The Middle Of A Linked List<\/h2>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5527 {\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_5527 .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_5527 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5527 .wpsm_nav-tabs > li.active > a, #tab_container_5527 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5527 .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_5527 .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_5527 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5527 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5527 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5527 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5527 .wpsm_nav-tabs > li > a:hover , #tab_container_5527 .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_5527 .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_5527 .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_5527 .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_5527 .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_5527 .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_5527 .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_5527 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5527 .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_5527 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5527 .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_5527 .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_5527\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5527\">\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_5527_1\" aria-controls=\"tabs_desc_5527_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\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_5527\">\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_5527_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"c\"} -->\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#include&lt;stdio.h&gt;\r\n#include&lt;stdlib.h&gt;\r\n\r\n\/\/ Node structure of a linked list node\r\nstruct Node\r\n{\r\n    int data;\r\n    struct Node* next;\r\n};\r\n\r\n\/\/ Using this function we will find and print the middle of the linked list\r\nvoid findMiddle(struct Node *head)\r\n{\r\n    struct Node *slow_ptr = head;\r\n    struct Node *fast_ptr = head;\r\n\r\n    if (head!=NULL)\r\n    {\r\n        while (fast_ptr != NULL &amp;&amp; fast_ptr-&gt;next != NULL)\r\n        {\r\n            fast_ptr = fast_ptr-&gt;next-&gt;next;\r\n            slow_ptr = slow_ptr-&gt;next;\r\n        }\r\n        printf(&quot;The middle element is %d&#92;n&#92;n&quot;, slow_ptr-&gt;data);\r\n    }\r\n}\r\n\r\n\/\/ Using this function we will create a new node and will insert at the beginning of the list\r\nvoid push(struct Node** head_ref, int new_data)\r\n{\r\n    struct Node* new_node =\r\n        (struct Node*) malloc(sizeof(struct Node));\r\n\r\n    new_node-&gt;data = new_data;\r\n\r\n    new_node-&gt;next = (*head_ref);\r\n\r\n    (*head_ref) = new_node;\r\n}\r\n\r\n\/\/ Using this function we will print the linked list\r\nvoid printList(struct Node *ptr)\r\n{\r\n    while (ptr != NULL)\r\n    {\r\n        printf(&quot;%d-&gt;&quot;, ptr-&gt;data);\r\n        ptr = ptr-&gt;next;\r\n    }\r\n    printf(&quot;NULL&#92;n&quot;);\r\n}\r\n\r\n\/\/ Driver Function\r\nint main()\r\n{\r\n    struct Node* head = NULL;\r\n    int i;\r\n    push(&amp;head,8);\r\n    push(&amp;head,4);\r\n    push(&amp;head,15);\r\n    push(&amp;head,10);\r\n    push(&amp;head,5);\r\n    printf(&quot;The Linked List is : &quot;);\r\n    printList(head);\r\n    findMiddle(head);\r\n    return 0;\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\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_5527 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_5527 a\"),jQuery(\"#tab-content_5527\"));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<pre><code>Output:\nThe Linked List is : 5->10->15->4->8->NULL\nThe middle element is 15<\/code><\/pre>\n<p><strong>Time Complexity To Make C Function To Print The Middle Of A Linked List:<\/strong> O(n), a single list traversal is needed.<\/p>\n<p>This blog had discussed both the optimized as well as naive approach to make C function to print the middle of a linked list. This is an important concept when it comes to coding interviews.  The efficiency of this implementation is what makes this question an important one for coding interviews. If you want to solve more questions on Linked List, which is curated by our expert mentors at PrepBytes, you can follow this link <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Linked List<\/a>.<\/p>\n<h2>FAQ<\/h2>\n<p><strong>1. Can we add an element in the middle of Linkedlist?<\/strong><br \/>\nYou can add elements to either the beginning, middle or end of the linked list.<\/p>\n<p><strong>2. What is the time complexity to print the middle element in the linked list?<\/strong><br \/>\nThe running time of finding the middle element this way with two pointers is O(n) because once we pass through the entire linked list of n elements, the slower pointer is at the middle node already.<\/p>\n<p><strong>3. How will you find the middle of a Linkedlist in a single iteration?<\/strong><br \/>\nIn each iteration, the ptr1 will access the two nodes and the ptr2 will access the single node of the linked list. Now, when the ptr1 reaches the end of the linked list, the ptr2 will be in the middle. In this way, we are able to get the middle of the linked list in a single iteration.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog will discuss how to make a C function to print the middle of a linked list. Linked list is one of the most interesting topics when you start practicing data structures. This blog is having both a naive and optimal approach to make a c function to print the middle of a linked [&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-5526","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>Write a C function to print the middle of a linked list<\/title>\n<meta name=\"description\" content=\"In this article, we have tried to explain the most efficient approach to find the middle of a linked list.\" \/>\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\/write-a-c-function-to-print-the-middle-of-a-linked-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Write a C function to print the middle of a linked list\" \/>\n<meta property=\"og:description\" content=\"In this article, we have tried to explain the most efficient approach to find the middle of a linked list.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/\" \/>\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-10-11T07:43:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-12-01T06:24:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Write a C function to print the middle of a linked list\",\"datePublished\":\"2021-10-11T07:43:02+00:00\",\"dateModified\":\"2022-12-01T06:24:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/\"},\"wordCount\":1233,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/\",\"name\":\"Write a C function to print the middle of a linked list\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png\",\"datePublished\":\"2021-10-11T07:43:02+00:00\",\"dateModified\":\"2022-12-01T06:24:12+00:00\",\"description\":\"In this article, we have tried to explain the most efficient approach to find the middle of a linked list.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#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\":\"Write a C function to print the middle of a linked list\"}]},{\"@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":"Write a C function to print the middle of a linked list","description":"In this article, we have tried to explain the most efficient approach to find the middle of a linked list.","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\/write-a-c-function-to-print-the-middle-of-a-linked-list\/","og_locale":"en_US","og_type":"article","og_title":"Write a C function to print the middle of a linked list","og_description":"In this article, we have tried to explain the most efficient approach to find the middle of a linked list.","og_url":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-10-11T07:43:02+00:00","article_modified_time":"2022-12-01T06:24:12+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Write a C function to print the middle of a linked list","datePublished":"2021-10-11T07:43:02+00:00","dateModified":"2022-12-01T06:24:12+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/"},"wordCount":1233,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/","url":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/","name":"Write a C function to print the middle of a linked list","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png","datePublished":"2021-10-11T07:43:02+00:00","dateModified":"2022-12-01T06:24:12+00:00","description":"In this article, we have tried to explain the most efficient approach to find the middle of a linked list.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645011930920-Article_194.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/write-a-c-function-to-print-the-middle-of-a-linked-list\/#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":"Write a C function to print the middle of a linked list"}]},{"@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\/5526","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=5526"}],"version-history":[{"count":8,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5526\/revisions"}],"predecessor-version":[{"id":10859,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5526\/revisions\/10859"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}