{"id":71804,"date":"2022-06-14T08:52:41","date_gmt":"2022-06-14T03:22:41","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/"},"modified":"2024-09-12T14:59:52","modified_gmt":"2024-09-12T09:29:52","slug":"reverse-linked-list","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/","title":{"rendered":"How to Reverse Linked List in Java?"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li><a href=\"#introduction\">Introduction <\/a><\/li><li><a href=\"#recursive-approach\">Recursive Approach(Algorithms, Code and Output)<\/a><\/li><li><a href=\"#iterative-approach\">Iterative Approach(Algorithms, Code and Output)<\/a><\/li><li><a href=\"#reversed-linked-list-faq\">Frequently Asked Questions on Reversed Linked List <\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction\"><strong>Introduction <\/strong><br><\/h2>\n\n\n\n<p><span style=\"color: initial;\"><\/span>A reversed linked list is the opposite of a linked list. So, we will first see what a linked list is. A <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/linkedlist\" target=\"_blank\" rel=\"noreferrer noopener\">linked list<\/a> is a type of data structure that consists of data and a pointer in which the pointer points to the next node is called a linked list. In simple language, we can say that a linked list is a data structure in which the data items are connected via links where each link is connected to another link. And when such a linked list is reversed, it is called Reversed Linked List. In a reversed linked list, the list is divided into two parts, such as the first part is the first node of the list, and the second part is the rest of the linked list. The last node is connected with the first node, and the first node is fixed.&nbsp;<\/p>\n\n\n\n<p>The linked list is a fundamental <a href=\"https:\/\/www.mygreatlearning.com\/blog\/data-structure-tutorial-for-beginners\/\" target=\"_blank\" rel=\"noreferrer noopener\">data structure<\/a> that has subtypes such as stack and queues. Several operations can be performed in a reversed linked list, just like we do in the simply linked list like Insertion, deletion, updating, etc.&nbsp;<\/p>\n\n\n\n<p>In this article, we are going to understand some useful examples with their basic concepts. We will also see the implementation of Reverse Linked List in various <a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-are-the-best-programming-languages-to-learn\/\" target=\"_blank\" rel=\"noreferrer noopener\">programming languages<\/a> that will help you better understand the logic behind its implementation.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"recursive-approachalgorithms-code-and-output\"><strong>Recursive Approach(Algorithms, Code and Output)<\/strong><br><\/h2>\n\n\n\n<p><span style=\"color: initial;\"><\/span>To apply the recursive approach for a reverse linked list, we are required to divide the linked list into two different parts such as the first node and the remaining list. After that, we can call the recursion for the other part of the list that maintains the connection between nodes.&nbsp;<\/p>\n\n\n\n<p>The picture below depicts what exactly the recursive approach does:<\/p>\n\n\n<figure class=\"wp-block-image size-full zoomable\" data-full=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list-.png\"><img decoding=\"async\" width=\"900\" height=\"900\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list-.png\" alt=\"recursive approach\" class=\"wp-image-71864\" srcset=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list-.png 900w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list--300x300.png 300w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list--150x150.png 150w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list--768x768.png 768w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list--696x696.png 696w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list--420x420.png 420w, https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/Reversed-linked-list--96x96.png 96w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Implementation: <\/strong>Now, let us see the implementation of the Reverse Linked list in various programming languages using the recursive approach below. But, first, we will see the common algorithm that is used in the recursive approach:<\/li><\/ul>\n\n\n\n<p><strong>Algorithm:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Divide the Linked list into two parts where the first part is the first node and the second part is the remaining list.<\/li><li>Call the recursion for the rest of the linked list to make it in reversed order.<\/li><li>Link the rest of the list with the first node.<\/li><li>Set the head pointer to the first node only.<\/li><\/ul>\n\n\n\n<p>As we just see how the algorithm of Reverse linked list for recursion works, now let us see its implementation in some common programming languages.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>In C++&nbsp;:&nbsp;<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\nusing namespace std;\nstruct LinkNode\n{\n    int data;\n    LinkNode * next;\n};\nvoid printList(LinkNode * head)\n{\n    LinkNode * pointer = head;\n    while (pointer)\n    {\n        cout &lt;&lt; pointer-&gt;data &lt;&lt; \" \u2014&gt; \";\n        pointer = pointer-&gt;next;\n    }\n    cout &lt;&lt; \"nullPointer\" &lt;&lt; endl;\n}\nvoid push(LinkNode * &amp;headRef, int data)\n{\n    LinkNode* newNode = new LinkNode();\n    newNode-&gt;data = data;\n    newNode-&gt;next = headRef; \n    headRef = newNode;\n}\nvoid reverseLinked(LinkNode * head, LinkNode * &amp;headRef)\n{\n    LinkNode * first;\n    LinkNode * rest;\n    if (head == nullPointer) {\n        return;\n    }\n    first = head;          \n    rest = first-&gt;next;    \n    if (rest == nullPointer)\n    {\n        headRef = first;\n        return;\n    } \n    reverseLinked(rest, headRef);\n    rest-&gt;next = first;\n    first-&gt;next = nullPointer; \n}\n \nvoid reverse(LinkNode* &amp;headRef) {\n    reverseLinked(headRef, headRef);\n}\nint main()\n{\n    vector&lt;int&gt; keys = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n    LinkNode * head = nullPointer;\n    for (int i = keys.size() - 1; i &gt;=0; i--) {\n        push(head, keys&#91;i]);\n    }\n    reverse(head);\n    printList(head);\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-left\"><strong>Output<\/strong><\/p>\n\n\n\n<p>9 -&gt; 8 -&gt; 7 -&gt; 6 \u2014&gt; 5 \u2014&gt; 4 \u2014&gt; 3 \u2014&gt; 2 \u2014&gt; 1 \u2014&gt; nullPointer<\/p>\n\n\n\n<p><strong>Time Complexity:<\/strong>&nbsp;O(n)&nbsp;<br><strong>Space Complexity:<\/strong>&nbsp;O(1)<\/p>\n\n\n\n<p><strong>In Java<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class LinkNode\n{\n    int data;\n    LinkNode next;\n \n    LinkNode(int data) {\n        this.data = data;\n    }\n}\n \nclass Main\n{\n  \n    public static void printList(LinkNode head)\n    {\n        LinkNode pointer = head;\n        while (pointer != null)\n        {\n            System.out.print(pointer.data + \" \u2014&gt; \");\n            pointer = pointer;\n        }\n        System.out.println(\"null\");\n    }\n \n   \n    public static LinkNode push(LinkNode head, int data)\n    {\n        LinkNode node = new LinkNode(data);\n        node.next = head;\n        return node;\n    }\n \n  \n    public static LinkNode reverse(LinkNode head, Node firstNode)\n    {\n        LinkNode first, rest; \n        if (head == null) {\n            return firstNode;\n        } \n        first = head;           \n        rest = first.next;      \n        if (rest == null)\n        {  \n            firstNode = first;\n            return firstNode;\n        }\n        firstNode = reverse(rest, firstNode);\n        rest.next = first;\n        first.next = null; \n \n        return firstNode;\n    }\n    public static LinkNode reverse(LinkNode head) {\n        return reverse(head, head);\n    }\n    public static void main(String&#91;] args)\n    {\n        int&#91;] keys = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n \n        LinkNode head = null;\n        for (int i = keys.length - 1; i &gt;=0; i--) {\n            head = push(head, keys&#91;i]);\n        }\n \n        head = reverse(head);\n        printList(head);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong>&nbsp;<\/p>\n\n\n\n<p>9 -&gt; 8 -&gt; 7 -&gt; 6 \u2014&gt; 5 \u2014&gt; 4 \u2014&gt; 3 \u2014&gt; 2 \u2014&gt; 1 \u2014&gt; null<strong>&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>Time Complexity:<\/strong>&nbsp;O(n)&nbsp;<br><strong>Space Complexity:<\/strong>&nbsp;O(1)<\/p>\n\n\n\n<p><strong>In Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class LinkNode:\n    def __init__(self, data, next=None):\n        self.data = data\n        self.next = next\ndef printLnkdLst(head):\n    ptr = head\n    while ptr:\n        print(ptr.data, end=' \u2014&gt; ')\n        ptr = ptr.next\n    print('None') \ndef reverse(head, firstNode): \n    if head is None:\n        return firstNode \n    first = head               \n    rest = first.next \n    if rest is None:   \n        firstNode = first\n        return firstNode\n    firstNode = reverse(rest, firstNode)\n    rest.next = first\n    first.next = None\n    return firstNode\ndef reverseLnkdList(head):\n    return reverse(head, head)\nif __name__ == '__main__':\n    head = None\n    for i in reversed(range(9)):\n        head = LinkNode(i + 1, head)\n    head = reverseLnkdList(head)\n    printLnkdLst(head)\n<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong>&nbsp;<\/p>\n\n\n\n<p>9 -&gt; 8 -&gt; 7 -&gt; 6 \u2014&gt; 5 \u2014&gt; 4 \u2014&gt; 3 \u2014&gt; 2 \u2014&gt; 1 \u2014&gt; None<\/p>\n\n\n\n<p><strong>Time Complexity:<\/strong>&nbsp;O(n)&nbsp;<br><strong>Space Complexity:<\/strong>&nbsp;O(1)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"iterative-approachalgorithms-code-and-output\"><strong>Iterative Approach(Algorithms, Code and Output)<\/strong><br><\/h2>\n\n\n\n<p id=\"iterative-approach\"><strong>Algorithm:&nbsp;<\/strong><\/p>\n\n\n\n<p>In this approach, three-pointers will be initialized first.<\/p>\n\n\n\n<p>Iterate in the linked list until it is not empty.<\/p>\n\n\n\n<p>Return the previous pointer that will work as the first node for the reversed linked list.&nbsp;<\/p>\n\n\n\n<p>The other pointers are also repeated iteratively until it reaches the end of the linked list.&nbsp;<\/p>\n\n\n\n<p>The final list will be a reversed linked list.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"implementation\"><strong>Implementation&nbsp;<\/strong><\/h4>\n\n\n\n<p><strong>In C++<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;bits\/stdc++.h&gt;\n \nusing namespace std;\n \nstruct linkednode {\n    int data;\n    struct linkednode * next;\n};\nvoid push(struct linkednode **head_ref, int data) {\n    struct linkednode *linkednode;\n    linkednode = (struct linkednode*)malloc(sizeof(struct linkednode));\n    linkednode-&gt;data = data;\n    linkednode-&gt;next = (*head_ref);\n    (*head_ref) = linkednode;\n}\nvoid reverse(struct linkednode **head_ref) {\n    struct linkednode *temp = NULL;\n    struct linkednode *prev = NULL;\n    struct linkednode *current = (*head_ref);\n    while(current != NULL) {\n        temp = current-&gt;next;\n        current-&gt;next = prev;\n        prev = current;\n        current = temp;\n    }\n    (*head_ref) = prev;\n}\n\nvoid printallnodes(struct linkednode *head) {\n    while(head != NULL) {\n        cout&lt;&lt;head-&gt;data&lt;&lt;\" \";\n        head = head-&gt;next;\n    }\n}\nint main() {\n    struct linkednode *head = NULL;\n    push(&amp;head, 0);\n    push(&amp;head, 1);\n    push(&amp;head, 8);\n    push(&amp;head, 0);\n    push(&amp;head, 4);\n    push(&amp;head, 6);\n    push(&amp;head, 9);\n    push(&amp;head, 10);\n    cout &lt;&lt; \"Before Reversing the Linked List: \" &lt;&lt; endl;\n    printallnodes(head);\n    reverse(&amp;head);\n    cout &lt;&lt; endl;\n    cout &lt;&lt; \"After Reversing the Linked List: \"&lt;&lt;endl;\n    printallnodes(head);\n    return 0;\n<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong>&nbsp;<\/p>\n\n\n\n<p>Before Reversing the Linked List:<\/p>\n\n\n\n<p>10 9 6 4 0 8 1 0<\/p>\n\n\n\n<p>After Reversing the Linked List:<\/p>\n\n\n\n<p>0 1 8 0 4 6 9 10<\/p>\n\n\n\n<p><strong>Time Complexity:<\/strong>&nbsp;O(n)&nbsp;<br><strong>Space Complexity:<\/strong>&nbsp;O(1)<\/p>\n\n\n\n<p><strong>In Java<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class LinkedNode\n{\n    int data;\n    LinkedNode next;\n \n    LinkedNode(int data, LinkedNode next)\n    {\n        this.data = data;\n        this.next = next;\n    }\n}\n \nclass Main\n{\n\n    public static void printLinkedList(LinkedNode firstNode)\n    {\n        LinkedNode pointer = firstNode;\n        while (pointer != null)\n        {\n            System.out.print(pointer.data + \" \u2014&gt; \");\n            pointer = pointer.next;\n        }\n \n        System.out.println(\"null\");\n    }\n \n\n    public static LinkedNode reverse(LinkedNode firstNode)\n    {\n        LinkedNode previous = null;\n        LinkedNode current = firstNode;\n \n\n        while (current != null)\n        {\n\n            LinkedNode next = current.next;\n \n            current.next = previous;    \n \n            previous = current;\n            current = next;\n        }\n \n\n        return previous;\n    }\n \n    public static void main(String&#91;] args)\n    {\n\n        int&#91;] keys = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n \n        LinkedNode firstNode = null;\n        for (int i = keys.length - 1; i &gt;= 0; i--) {\n            firstNode = new LinkedNode(keys&#91;i], firstNode);\n        }\n \n        firstNode = reverse(firstNode);\n        printLinkedList(firstNode);\n    }\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong>&nbsp;<\/p>\n\n\n\n<p>9 -&gt; 8 -&gt; 7 -&gt; 6 \u2014&gt; 5 \u2014&gt; 4 \u2014&gt; 3 \u2014&gt; 2 \u2014&gt; 1 \u2014&gt; null<strong>&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>Time Complexity:<\/strong>&nbsp;O(n)&nbsp;<br><strong>Space Complexity:<\/strong>&nbsp;O(1)<\/p>\n\n\n\n<p><strong>In Python<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class LinkedNode:\n    def __init__(self, data=None, next=None):\n        self.data = data\n        self.next = next\ndef printLinkedList(head):\n    pointer = head\n    while pointer:\n        print(pointer.data, end=' \u2014&gt; ')\n        pointer = pointer.next\n    print('None')\ndef reverse(head):\n    previous = None\n    current = head\n    while current:\n        next = current.next \n        current.next = previous        \n \n        previous = current\n        current = next\n    return previous\nif __name__ == '__main__':\n    head = None\n    for i in reversed(range(9)):\n        head = LinkedNode(i + 1, head)\n    head = reverse(head)\n    printLinkedList(head)\n<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong>&nbsp;<\/p>\n\n\n\n<p>9 -&gt; 8 -&gt; 7 -&gt; 6 \u2014&gt; 5 \u2014&gt; 4 \u2014&gt; 3 \u2014&gt; 2 \u2014&gt; 1 \u2014&gt; None<br><strong>Time Complexity:<\/strong>&nbsp;O(n)&nbsp;<br><strong>Space Complexity:<\/strong>&nbsp;O(1)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"frequently-asked-questions-on-reversed-linked-list\"><strong>Frequently Asked Questions on Reversed Linked List <\/strong><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1655174060189\"><strong class=\"schema-faq-question\"><strong>What is the time complexity of reversing a linked list by using a recursive approach?<\/strong><\/strong> <p class=\"schema-faq-answer\">The time complexity for reversing a linked list by recursive approach is: O(n)<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1655174079017\"><strong class=\"schema-faq-question\"><strong>What is the time complexity of reversing a linked list by using an iterative approach?<\/strong><br\/><\/strong> <p class=\"schema-faq-answer\">The time complexity for reversing a linked list by iterative approach is: O(1)<br\/><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1655174088766\"><strong class=\"schema-faq-question\"><strong>Is it possible to use Stack to reverse a linked list?<\/strong><\/strong> <p class=\"schema-faq-answer\">Yes, it's possible. You need to traverse the list and push all the nodes into the stack. After that, you again need to traverse the list to pop the values from the top of the stack and connect them in reverse order. The space complexity will also increase to O(n).<br\/><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1655174106980\"><strong class=\"schema-faq-question\"><strong>Do either of the approaches, i.e. recursive or iterative will change the address of a node?<\/strong><br\/><\/strong> <p class=\"schema-faq-answer\">No, it will not change the address of a node. But to be on the safer side, you should try to keep the address of the node from changing.<br\/><\/p> <\/div> <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><br><\/h2>\n\n\n\n<p><span style=\"color: initial;\"><\/span>The linked list is a very useful data structure and because of its importance reverse linked list also has its importance in specific cases. In this article, we discussed the concept of how we can reverse a linked list by two approaches i.e. recursive and iterative. Both of the approaches are very useful. We also discussed the <a href=\"https:\/\/www.mygreatlearning.com\/blog\/introduction-to-algorithms-uses-and-types\/\" target=\"_blank\" rel=\"noreferrer noopener\">algorithms<\/a> and their application in different programming languages that helped to better understand the logic behind reversing a linked list.&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Recursive Approach(Algorithms, Code and Output) Iterative Approach(Algorithms, Code and Output) Frequently Asked Questions on Reversed Linked List Introduction A reversed linked list is the opposite of a linked list. So, we will first see what a linked list is. A linked list is a type of data structure that consists of data and a [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":68394,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[],"content_type":[],"class_list":["post-71804","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Reverse Linked List in Java?<\/title>\n<meta name=\"description\" content=\"Reverse Linked List: This blog helps you to understand the implementation of Reverse Linked List in various programming languages.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Reverse Linked List in Java?\" \/>\n<meta property=\"og:description\" content=\"Reverse Linked List: This blog helps you to understand the implementation of Reverse Linked List in various programming languages.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-14T03:22:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-12T09:29:52+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1254\" \/>\n\t<meta property=\"og:image:height\" content=\"836\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"How to Reverse Linked List in Java?\",\"datePublished\":\"2022-06-14T03:22:41+00:00\",\"dateModified\":\"2024-09-12T09:29:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/\"},\"wordCount\":933,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/iStock-1277019303.jpg\",\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/\",\"name\":\"How to Reverse Linked List in Java?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/iStock-1277019303.jpg\",\"datePublished\":\"2022-06-14T03:22:41+00:00\",\"dateModified\":\"2024-09-12T09:29:52+00:00\",\"description\":\"Reverse Linked List: This blog helps you to understand the implementation of Reverse Linked List in various programming languages.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174060189\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174079017\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174088766\"},{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174106980\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/iStock-1277019303.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/05\\\/iStock-1277019303.jpg\",\"width\":1254,\"height\":836,\"caption\":\"reversed linked list\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Reverse Linked List in Java?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174060189\",\"position\":1,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174060189\",\"name\":\"What is the time complexity of reversing a linked list by using a recursive approach?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The time complexity for reversing a linked list by recursive approach is: O(n)\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174079017\",\"position\":2,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174079017\",\"name\":\"What is the time complexity of reversing a linked list by using an iterative approach?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The time complexity for reversing a linked list by iterative approach is: O(1)<br\\\/>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174088766\",\"position\":3,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174088766\",\"name\":\"Is it possible to use Stack to reverse a linked list?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes, it's possible. You need to traverse the list and push all the nodes into the stack. After that, you again need to traverse the list to pop the values from the top of the stack and connect them in reverse order. The space complexity will also increase to O(n).<br\\\/>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174106980\",\"position\":4,\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/reverse-linked-list\\\/#faq-question-1655174106980\",\"name\":\"Do either of the approaches, i.e. recursive or iterative will change the address of a node?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No, it will not change the address of a node. But to be on the safer side, you should try to keep the address of the node from changing.<br\\\/>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Reverse Linked List in Java?","description":"Reverse Linked List: This blog helps you to understand the implementation of Reverse Linked List in various programming languages.","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:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/","og_locale":"en_US","og_type":"article","og_title":"How to Reverse Linked List in Java?","og_description":"Reverse Linked List: This blog helps you to understand the implementation of Reverse Linked List in various programming languages.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2022-06-14T03:22:41+00:00","article_modified_time":"2024-09-12T09:29:52+00:00","og_image":[{"width":1254,"height":836,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"How to Reverse Linked List in Java?","datePublished":"2022-06-14T03:22:41+00:00","dateModified":"2024-09-12T09:29:52+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/"},"wordCount":933,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg","articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/","url":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/","name":"How to Reverse Linked List in Java?","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg","datePublished":"2022-06-14T03:22:41+00:00","dateModified":"2024-09-12T09:29:52+00:00","description":"Reverse Linked List: This blog helps you to understand the implementation of Reverse Linked List in various programming languages.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174060189"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174079017"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174088766"},{"@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174106980"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg","width":1254,"height":836,"caption":"reversed linked list"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"How to Reverse Linked List in Java?"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174060189","position":1,"url":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174060189","name":"What is the time complexity of reversing a linked list by using a recursive approach?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The time complexity for reversing a linked list by recursive approach is: O(n)","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174079017","position":2,"url":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174079017","name":"What is the time complexity of reversing a linked list by using an iterative approach?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The time complexity for reversing a linked list by iterative approach is: O(1)<br\/>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174088766","position":3,"url":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174088766","name":"Is it possible to use Stack to reverse a linked list?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes, it's possible. You need to traverse the list and push all the nodes into the stack. After that, you again need to traverse the list to pop the values from the top of the stack and connect them in reverse order. The space complexity will also increase to O(n).<br\/>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174106980","position":4,"url":"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/#faq-question-1655174106980","name":"Do either of the approaches, i.e. recursive or iterative will change the address of a node?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"No, it will not change the address of a node. But to be on the safer side, you should try to keep the address of the node from changing.<br\/>","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg",1254,836,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303-1024x683.jpg",1024,683,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg",1254,836,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303.jpg",1254,836,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303-640x836.jpg",640,836,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/05\/iStock-1277019303-150x100.jpg",150,100,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Introduction Recursive Approach(Algorithms, Code and Output) Iterative Approach(Algorithms, Code and Output) Frequently Asked Questions on Reversed Linked List Introduction A reversed linked list is the opposite of a linked list. So, we will first see what a linked list is. A linked list is a type of data structure that consists of data and a&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/71804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=71804"}],"version-history":[{"count":10,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/71804\/revisions"}],"predecessor-version":[{"id":72090,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/71804\/revisions\/72090"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/68394"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=71804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=71804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=71804"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=71804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}