{"id":3167,"date":"2021-06-17T12:03:00","date_gmt":"2021-06-17T06:33:00","guid":{"rendered":"https:\/\/manorinfinity.com\/blog\/doubly-linked-list-declaration-traversing-bitsofcs\/"},"modified":"2021-06-17T12:03:00","modified_gmt":"2021-06-17T06:33:00","slug":"doubly-linked-list-declaration-traversing-bitsofcs","status":"publish","type":"post","link":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/","title":{"rendered":"Doubly Linked List | Declaration | Traversing | BitsOfCS"},"content":{"rendered":"<p><span style=\"background-color: white; color: #292929; font-family: courier; font-size: large;\"><\/p>\n<div style=\"text-align: center;\">\n<div style=\"clear: both; text-align: center;\"><\/div>\n<\/div>\n<div><span>We know that, in a singly linked list every elements (node) has a pointer to its next element (node) in the sequence. Hence, if we want to traverse the singly linked list then we can traverse in only one direction. We cannot traverse back in the singly linked list.&nbsp;<\/span><\/div>\n<div><span><br \/><\/span><\/div>\n<div><span>But now we want to traverse in the both direction i.e. in forward direction and backward direction. We can solve this kind of problem using doubly linked list.<\/span><\/div>\n<div><span><br \/><\/span><\/div>\n<div><span>&#8220;Doubly linked list is a sequence of nodes in which every node has a link to its previous node as well as next node in the sequence.&#8221;<\/span><\/div>\n<div><span>So, if we want to traverse forward in the linked list then we can use next field and if we want to traverse backward in the linked list then we can use previous field.<\/span><\/div>\n<div><span><b>Example<\/b>&#8211;<\/span><\/div>\n<div><span><br \/><\/span><\/div>\n<div style=\"text-align: center;\">\n<div style=\"clear: both; text-align: center;\"><span><img data-recalc-dims=\"1\" height=\"128\" width=\"300\" decoding=\"async\" border=\"0\" data-original-height=\"332\" data-original-width=\"776\" src=\"https:\/\/i0.wp.com\/explore.techenutia.com\/wp-content\/uploads\/2021\/06\/sd-300x128.png?resize=300%2C128&#038;ssl=1\" \/><\/span><\/div>\n<p><span><br \/><\/span><\/div>\n<div style=\"text-align: left;\"><span><br \/><\/span><\/div>\n<div style=\"text-align: left;\"><span>Also read: <a href=\"https:\/\/www.bitsofcs.xyz\/2021\/06\/singly-linked-list.html\" target=\"_blank\" rel=\"noopener noreferrer\">Singly Linked List<\/a><\/span><\/div>\n<div style=\"text-align: left;\"><span>Also read: <a href=\"https:\/\/www.bitsofcs.xyz\/2021\/06\/circular-linked-list.html\" target=\"_blank\" rel=\"noopener noreferrer\">Circular Linked List<\/a><\/span><\/div>\n<div style=\"text-align: left;\"><span>Also read: <a href=\"https:\/\/www.bitsofcs.xyz\/2021\/06\/doubly-circular-linked-list.html\" target=\"_blank\" rel=\"noopener noreferrer\">Circular Doubly Linked List<\/a><\/span><\/div>\n<div style=\"text-align: left;\"><\/div>\n<h2 style=\"text-align: left;\"><span>Declaring the Doubly Linked List:<\/span><\/h2>\n<div><span>We know that, we can implement a doubly linked list using <a href=\"https:\/\/www.bitsofcs.xyz\/2021\/06\/self-referential-structure.html\" target=\"_blank\" rel=\"noopener noreferrer\">self referential structure<\/a>. Because self referential structure is a structure that contains a data field and a prev_pointer field that points to the previous node in the list and a next_pointer field that points to the next node in the list.<\/span><\/div>\n<p><span><\/span><\/p>\n<div><span>This is how you can use the above definition to create every node in the doubly linked list. The data field stores an integer and *prev_link is a pointer that holds the address of the prev node in the linked list and *next_link is a pointer that holds the address of the next node in the linked list.<\/span><\/div>\n<div><span><br \/><\/span><\/div>\n<h2 style=\"text-align: left;\"><span>Traversing a Doubly Linked List:<\/span><\/h2>\n<div><span>In the below program I will show you how to create and traverse the doubly linked list in both direction. The above program have three functions-<\/span><\/div>\n<div>\n<ol>\n<li><span><span><b>create_list()<\/b> : to create the linked list.<\/span><\/span><\/li>\n<li><span><span><b>trav_f()<\/b> : to traverse the linked list in forward direction.<\/span><\/span><\/li>\n<li><span><span><b>trav_b()<\/b> : to traverse the linked list in backward direction.<\/span><\/span><\/li>\n<\/ol>\n<p><span><b>Example<\/b>&#8211;<\/span><\/div>\n<p><span><\/span><\/p>\n<div><span><b>Output<\/b>&#8211;<\/span><\/div>\n<div style=\"text-align: center;\"><span><\/p>\n<div style=\"clear: both; text-align: center;\"><img data-recalc-dims=\"1\" height=\"133\" width=\"300\" decoding=\"async\" alt=\"\" data-original-height=\"146\" data-original-width=\"329\" src=\"https:\/\/i0.wp.com\/explore.techenutia.com\/wp-content\/uploads\/2021\/06\/image-2-300x133.png?resize=300%2C133&#038;ssl=1\" \/><\/div>\n<div style=\"text-align: left;\"><\/div>\n<div style=\"text-align: left;\">This is how our doubly linked list looked like:<\/div>\n<div style=\"text-align: left;\"><\/div>\n<p><\/span><\/p>\n<div style=\"clear: both; text-align: center;\"><img data-recalc-dims=\"1\" height=\"94\" width=\"300\" decoding=\"async\" border=\"0\" data-original-height=\"242\" data-original-width=\"776\" src=\"https:\/\/i0.wp.com\/explore.techenutia.com\/wp-content\/uploads\/2021\/06\/doubly-2B-25281-2529-1-300x94.png?resize=300%2C94&#038;ssl=1\" \/><\/div>\n<div style=\"text-align: left;\"><\/div>\n<div style=\"text-align: left;\">If you want to understand the above program then <a href=\"https:\/\/www.bitsofcs.xyz\/2021\/06\/create-traverse-doubly-linked-list.html\" target=\"_blank\" rel=\"noopener noreferrer\">click here<\/a>!<\/div>\n<\/div>\n<div><span>If you find any problem related to this article, please comment below or contact me&nbsp;<\/span><a href=\"https:\/\/www.bitsofcs.xyz\/p\/contact-me.html\" style=\"background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #25a186; cursor: pointer; text-decoration-line: none;\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a><span>.<\/span><\/div>\n<p><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We know that, in a singly linked list every elements (node) has a pointer to its next element (node) in the sequence. Hence, if we want to traverse the singly linked list then we can traverse in only one direction. We cannot traverse back in the singly linked list.&nbsp; But&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/\">Read the post<span class=\"screen-reader-text\">Doubly Linked List | Declaration | Traversing | BitsOfCS<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":3190,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3167","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-infinity-fitness","excerpt","zoom","full-without-featured","even","excerpt-0"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.12 (Yoast SEO v26.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Doubly Linked List | Declaration | Traversing | BitsOfCS | ManOrInfinity<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Doubly Linked List | Declaration | Traversing | BitsOfCS\" \/>\n<meta property=\"og:description\" content=\"We know that, in a singly linked list every elements (node) has a pointer to its next element (node) in the sequence. Hence, if we want to traverse the singly linked list then we can traverse in only one direction. We cannot traverse back in the singly linked list.&nbsp; But&#8230;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/\" \/>\n<meta property=\"og:site_name\" content=\"ManOrInfinity\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-17T06:33:00+00:00\" \/>\n<meta name=\"author\" content=\"manorinfinity\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@manorinfinity\" \/>\n<meta name=\"twitter:site\" content=\"@manorinfinity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"manorinfinity\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/\"},\"author\":{\"name\":\"manorinfinity\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"headline\":\"Doubly Linked List | Declaration | Traversing | BitsOfCS\",\"datePublished\":\"2021-06-17T06:33:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/\"},\"wordCount\":379,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"image\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#primaryimage\"},\"thumbnailUrl\":\"\",\"articleSection\":[\"Infinity Fitness\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/\",\"url\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/\",\"name\":\"Doubly Linked List | Declaration | Traversing | BitsOfCS | ManOrInfinity\",\"isPartOf\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#primaryimage\"},\"thumbnailUrl\":\"\",\"datePublished\":\"2021-06-17T06:33:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/manorinfinity.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Doubly Linked List | Declaration | Traversing | BitsOfCS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#website\",\"url\":\"https:\/\/manorinfinity.com\/blog\/\",\"name\":\"ManOrInfinity\",\"description\":\"Thrive towards greatness\",\"publisher\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/manorinfinity.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901\",\"name\":\"manorinfinity\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png\",\"contentUrl\":\"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png\",\"width\":282,\"height\":260,\"caption\":\"manorinfinity\"},\"logo\":{\"@id\":\"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/\"},\"description\":\"Complex Problem Solver, Outloud Thinker, An Outstanding Writer, and a very curious human being\",\"sameAs\":[\"http:\/\/manorinfinity.com\"],\"url\":\"https:\/\/manorinfinity.com\/blog\/author\/manorinfinity\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Doubly Linked List | Declaration | Traversing | BitsOfCS | ManOrInfinity","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:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/","og_locale":"en_US","og_type":"article","og_title":"Doubly Linked List | Declaration | Traversing | BitsOfCS","og_description":"We know that, in a singly linked list every elements (node) has a pointer to its next element (node) in the sequence. Hence, if we want to traverse the singly linked list then we can traverse in only one direction. We cannot traverse back in the singly linked list.&nbsp; But&#8230;","og_url":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/","og_site_name":"ManOrInfinity","article_published_time":"2021-06-17T06:33:00+00:00","author":"manorinfinity","twitter_card":"summary_large_image","twitter_creator":"@manorinfinity","twitter_site":"@manorinfinity","twitter_misc":{"Written by":"manorinfinity","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#article","isPartOf":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/"},"author":{"name":"manorinfinity","@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"headline":"Doubly Linked List | Declaration | Traversing | BitsOfCS","datePublished":"2021-06-17T06:33:00+00:00","mainEntityOfPage":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/"},"wordCount":379,"commentCount":0,"publisher":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"image":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#primaryimage"},"thumbnailUrl":"","articleSection":["Infinity Fitness"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/","url":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/","name":"Doubly Linked List | Declaration | Traversing | BitsOfCS | ManOrInfinity","isPartOf":{"@id":"https:\/\/manorinfinity.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#primaryimage"},"image":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#primaryimage"},"thumbnailUrl":"","datePublished":"2021-06-17T06:33:00+00:00","breadcrumb":{"@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/manorinfinity.com\/blog\/2021\/06\/17\/doubly-linked-list-declaration-traversing-bitsofcs\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/manorinfinity.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Doubly Linked List | Declaration | Traversing | BitsOfCS"}]},{"@type":"WebSite","@id":"https:\/\/manorinfinity.com\/blog\/#website","url":"https:\/\/manorinfinity.com\/blog\/","name":"ManOrInfinity","description":"Thrive towards greatness","publisher":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/manorinfinity.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/1172b1895b5eb7e49cc8640e49255901","name":"manorinfinity","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/","url":"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png","contentUrl":"http:\/\/manorinfinity.com\/wp-content\/uploads\/2023\/06\/moi-logo.png","width":282,"height":260,"caption":"manorinfinity"},"logo":{"@id":"https:\/\/manorinfinity.com\/blog\/#\/schema\/person\/image\/"},"description":"Complex Problem Solver, Outloud Thinker, An Outstanding Writer, and a very curious human being","sameAs":["http:\/\/manorinfinity.com"],"url":"https:\/\/manorinfinity.com\/blog\/author\/manorinfinity\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/comments?post=3167"}],"version-history":[{"count":0,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/posts\/3167\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/media?parent=3167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/categories?post=3167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/manorinfinity.com\/blog\/wp-json\/wp\/v2\/tags?post=3167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}