{"id":12629,"date":"2023-02-09T11:05:08","date_gmt":"2023-02-09T11:05:08","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=12629"},"modified":"2023-03-02T06:30:42","modified_gmt":"2023-03-02T06:30:42","slug":"stack-implementation-using-linked-list","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/","title":{"rendered":"Stack Implementation using Linked List"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg\" alt=\"\" \/><\/p>\n<p>In this article, we will learn about what is stack and about various operations performed on Stack in Data Structure, stack implementation using linked list with the dry run of code. We will also enlist various advantages and disadvantages of implementation of Stack using Linked List. In the last, we will discuss some of the applications of Stack in Data Structure.<\/p>\n<h2>Stack in Data Structure: Introduction<\/h2>\n<p>A stack is a linear data structure in computer science that operates on the Last-In-First-Out (LIFO) principle. A stack stores elements in a sequential manner where elements are inserted (pushed) onto the top of the stack and removed (popped) from the top. The new element to be added is at the top of the stack. The operations performed on a stack include push, pop, and peek. Stacks are widely used in computer algorithms and programs for data manipulation, function calls, and expression evaluations.<\/p>\n<h2>Operations performed on Stack in Data Structure<\/h2>\n<p>The main operations performed on a stack data structure are:<\/p>\n<ul>\n<li><strong>push():<\/strong> This method adds an element to the top of the stack<\/li>\n<li><strong>pop():<\/strong> This method removes an element from the top of the stack<\/li>\n<li><strong>peek():<\/strong> This method returns the element at the top of the stack without removing it<\/li>\n<li><strong>isEmpty():<\/strong> This method returns true if the stack is empty, otherwise false<\/li>\n<li><strong>size():<\/strong> This method Returns the number of elements in the stack<\/li>\n<\/ul>\n<p>Stacks are LIFO (Last In First Out) data structures, meaning that the last element added to the stack will be the first one to be removed. These operations make it a useful data structure for various algorithms, such as maintaining function call history, evaluating mathematical expressions, and implementing undo-redo functionality in applications.<\/p>\n<h2>Stack Implementation<\/h2>\n<p>A stack in data structure can be implemented using an array or a linked list.<\/p>\n<ul>\n<li><strong>Stack Implementation using Array:<\/strong> In this approach, an array is used to store the elements of the stack. The top of the stack is kept track of using a variable that points to the index of the topmost element. The basic operations performed on a stack such as push, pop, and peek are implemented by adjusting the value of the top variable.<\/li>\n<li><strong>Stack Implementation using Linked list:<\/strong> In this approach, each element of the stack is represented as a node in a linked list. The head of the Singly Linked List represents the top of the stack. The basic operations are performed by updating the links between the nodes in the linked list. This implementation is more flexible as it can grow and shrink dynamically as elements are added and removed from the stack.<\/li>\n<\/ul>\n<h3>Stack Implementation using Linked List<\/h3>\n<p>We can implement the stack using Linked List. Let us understand this in detail.<\/p>\n<p><strong>Input:<\/strong> We give 4 3 2 1.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229898-Stack%20Implementation%20using%20Linked%20List1.png\" alt=\"\" \/><\/p>\n<p><strong>Output:<\/strong> If the input is 4 3 2 1, then our singly linked list, which will have all functionalities of a stack, will be<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229898-Stack%20Implementation%20using%20Linked%20List2.png\" alt=\"\" \/><\/p>\n<p>where the head of the linked list is pointing to the 1.<\/p>\n<h4>Understanding of the Stack Implementation using Linked List<\/h4>\n<p>Let\u2019s see how a stack works.<\/p>\n<ul>\n<li>It follows the LIFO(last in first out) principle, i.e., the element inserted last in the stack will be the first one accessible to us if we access elements from the stack.<\/li>\n<li>Suppose we inserted elements in the stack in order 4,3,2,1, and now if we want to access elements from the stack, the order in which the elements will be accessible to us will be 1,2,3,4.<\/li>\n<\/ul>\n<p>Now, let&#8217;s recall what a Singly Linked List is.<\/p>\n<ul>\n<li>A Singly Linked List is a linear data structure containing nodes, and each node have a data part and a next pointer that points to the next node in the linked list.<\/li>\n<li>If we can amend the inserting new node operation in a singly linked list in such a way that the current inserted element is always at the head of the linked list and is the first element accessible to us if we want to access an element from the linked list, then we can see that our linked list is mimicking the behavior of stack.<\/li>\n<li>Similarly, we will try to think of other stack operations and how we can implement these operations using a singly linked list.<\/li>\n<\/ul>\n<p>Let us have a glance at the algorithm.<\/p>\n<h3>Approach and Algorithm of Stack using Linked List<\/h3>\n<p>There are mainly 5 functions of a stack. We will learn each function\u2019s approach and algorithm one by one.<\/p>\n<ol>\n<li>\n<p><strong>push()<\/strong><\/p>\n<ul>\n<li>In the push function, we push the element into the stack and make it the top.<\/li>\n<li>So, to do the same with a singly linked list, we will check if the list is Null or not.\n<ul>\n<li>If it is Null, then make the new node the head.<\/li>\n<li>If the list is not empty, then make the next of the new node point to the head of the list. In the end, make the new node the head of the list. In this way, we are first adding the element at the head, and the making it our head.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>pop()<\/strong><\/p>\n<ul>\n<li>In the pop function, we pop the topmost element of the stack.<\/li>\n<li>So, to do the same with a singly linked list, first, we will check if the list is Null or not.\n<ul>\n<li>If it is Null, then return NULL.<\/li>\n<li>If there is only one node in the list, then remove the head, and return NULL.<\/li>\n<li>If both the above base cases fail:<\/li>\n<li>We will create a new node temp and make it point to the head.<\/li>\n<li>Now, we will do <strong>head = head \u2192 next<\/strong> to make the 2nd node our new head.<\/li>\n<li>After this, we will do <strong>temp \u2192 next = NULL<\/strong>, and free (temp).<\/li>\n<li>In this way, we are making deleting the 1st node of the list and making the 2nd node our new head.<\/li>\n<li><strong>Remember<\/strong> \u2013 We are using 1 based indexing in the above approach.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>peek()<\/strong><\/p>\n<ul>\n<li>In the peek function, we have to return the top element of the stack without deleting it.<\/li>\n<li>So, to do the same with a singly linked list, first, we will check if the list is empty or not.\n<ul>\n<li>If the list is empty, we will simply exit as there is no data in the list.<\/li>\n<li>If the list is not empty, we will just return the <strong>head \u2192 data<\/strong>, as it is the top element of the stack.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>isEmpty()<\/strong><\/p>\n<ul>\n<li>In the isEmpty function, we have to check whether the stack is empty or not.<\/li>\n<li>So, to do the same with a singly linked list, we will just check if the head is NULL or not.\n<ul>\n<li>If the head is NULL, it means that the list is empty, so we will return true.<\/li>\n<li>If the head is not NULL, it means that the list is not empty, so we will return false.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>display()<\/strong><\/p>\n<ul>\n<li>In the display function, we have to print the stack.<\/li>\n<li>So, to do the same with a singly linked list, we will do a list traversal and print the elements of list one by one.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3>Dry Run of Stack using Linked List<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229898-Stack%20Implementation%20using%20Linked%20List3.png\" alt=\"\" \/><\/p>\n<h3>Code for Stack Implementation using Linked List<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_12639 {\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_12639 .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_12639 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_12639 .wpsm_nav-tabs > li.active > a, #tab_container_12639 .wpsm_nav-tabs > li.active > a:hover, #tab_container_12639 .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_12639 .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_12639 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_12639 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_12639 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_12639 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_12639 .wpsm_nav-tabs > li > a:hover , #tab_container_12639 .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_12639 .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_12639 .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_12639 .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_12639 .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_12639 .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_12639 .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_12639 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_12639 .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_12639 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_12639 .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_12639 .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_12639\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_12639\">\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_12639_1\" aria-controls=\"tabs_desc_12639_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_12639_2\" aria-controls=\"tabs_desc_12639_2\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_12639_3\" aria-controls=\"tabs_desc_12639_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_12639\">\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_12639_1\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\">#include &lt;bits\/stdc++.h&gt;\r\nusing namespace std;\r\n\r\n\r\nstruct Node\r\n{\r\n    int data;\r\n    struct Node* link;\r\n};\r\n\r\nstruct Node* top;\r\n\r\n\/\/ Using this function we will be pushing elements into the stack\r\nvoid push(int data)\r\n{\r\n\r\n    struct Node* tem;\r\n    tem = new Node();\r\n\r\n    if (!tem)\r\n    {\r\n        cout &lt;&lt; \"&#92;nHeap Overflow\";\r\n        exit(1);\r\n    }\r\n\r\n    tem-&gt;data = data;\r\n\r\n    tem-&gt;link = top;\r\n\r\n    top = tem;\r\n}\r\n\r\n\/\/ Using this function we will be checking whether the stack is empty or not\r\nint isEmpty()\r\n{\r\n    return top == NULL;\r\n}\r\n\r\n\/\/ Using this function we will return the top element of the stack\r\nint peek()\r\n{\r\n\r\n    if (!isEmpty())\r\n        return top-&gt;data;\r\n    else\r\n        exit(1);\r\n}\r\n\r\n\/\/ Using this function we will pop the top element of the stack\r\nvoid pop()\r\n{\r\n    struct Node* tem;\r\n\r\n    if (top == NULL)\r\n    {\r\n        cout &lt;&lt; \"&#92;nStack Underflow\" &lt;&lt; endl;\r\n        exit(1);\r\n    }\r\n    else\r\n    {\r\n        tem = top;\r\n\r\n        top = top-&gt;link;\r\n\r\n        tem-&gt;link = NULL;\r\n\r\n        free(tem);\r\n    }\r\n}\r\n\r\n\/\/ this function will be used to display the items of the stack\r\nvoid display()\r\n{\r\n    struct Node* tem;\r\n\r\n    if (top == NULL)\r\n    {\r\n        cout &lt;&lt; \"&#92;nStack Underflow\";\r\n        exit(1);\r\n    }\r\n    else\r\n    {\r\n        tem = top;\r\n        while (tem != NULL)\r\n        {\r\n\r\n            cout &lt;&lt; tem-&gt;data &lt;&lt; \"-&gt; \";\r\n\r\n            tem = tem-&gt;link;\r\n        }\r\n    }\r\n}\r\n\r\nint main()\r\n{\r\n    push(4);\r\n    push(3);\r\n    push(2);\r\n    push(1);\r\n    display();\r\n\r\n    cout &lt;&lt; \"&#92;nTop element is \"&lt;&lt; peek() &lt;&lt; endl;\r\n\r\n    pop();\r\n    pop();\r\n\r\n    cout&lt;&lt;\"Stack after popping 2 times &#92;n\";\r\n    display();\r\n\r\n    cout &lt;&lt; \"&#92;nTop element is \"&lt;&lt; peek() &lt;&lt; endl;\r\n        \r\n    return 0;\r\n}<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_12639_2\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\">import static java.lang.System.exit;\r\n\r\nclass StackUsingLinkedlist {\r\n\r\n    private class Node {\r\n\r\n        int data;\r\n        Node link; \r\n    }\r\n\r\n    Node top;\r\n\r\n    StackUsingLinkedlist()\r\n    {\r\n        this.top = null;\r\n    }\r\n\r\n    \/\/ Using this function we will be pushing elements into the stack\r\n    public void push(int x) \r\n    {\r\n\r\n        Node temp = new Node();\r\n\r\n        if (temp == null) {\r\n            System.out.print(\"&#92;nHeap Overflow\");\r\n            return;\r\n        }\r\n\r\n        temp.data = x;\r\n\r\n        temp.link = top;\r\n\r\n        top = temp;\r\n    }\r\n\r\n    \/\/ Using this function we will be checking whether the stack is empty or not\r\n    public boolean isEmpty()\r\n    {\r\n        return top == null;\r\n    }\r\n\r\n    \/\/ using this function we will return the top element of the stack\r\n    public int peek()\r\n    {\r\n\r\n        if (!isEmpty()) {\r\n            return top.data;\r\n        }\r\n        else {\r\n            System.out.println(\"Stack is empty\");\r\n            return -1;\r\n        }\r\n    }\r\n\r\n    \/\/ Using this function we will pop the top element of the stack\r\n    public void pop() \r\n    {\r\n\r\n        if (top == null) {\r\n            System.out.print(\"&#92;nStack Underflow\");\r\n            return;\r\n        }\r\n\r\n        top = (top).link;\r\n    }\r\n\r\n    \/\/ this function will be used to display the items of the stack\r\n    public void display()\r\n    {\r\n\r\n        if (top == null) {\r\n            System.out.printf(\"&#92;nStack Underflow\");\r\n            exit(1);\r\n        }\r\n        else {\r\n            Node temp = top;\r\n            while (temp != null) {\r\n\r\n                System.out.printf(\"%d-&gt;\", temp.data);\r\n\r\n                temp = temp.link;\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\nclass PrepBytes {\r\n    public static void main(String[] args)\r\n    {\r\n\r\n        StackUsingLinkedlist stk = new StackUsingLinkedlist();\r\n\r\n        stk.push(4);\r\n        stk.push(3);\r\n        stk.push(2);\r\n        stk.push(1);\r\n\r\n        stk.display();\r\n\r\n        System.out.printf(\"&#92;nTop element is %d&#92;n\", stk.peek());\r\n        System.out.println(\"Stack after popping 2 times\");\r\n        stk.pop();\r\n        stk.pop();\r\n\r\n        stk.display();\r\n\r\n        System.out.printf(\"&#92;nTop element is %d&#92;n\", stk.peek());\r\n    }\r\n}<\/pre>\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_12639_3\">\r\n\t\t\t\t\t\t\t\t<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\"># your code goes hereclass Node:\r\nclass Node: \r\n    def __init__(self,data):\r\n        self.data = data\r\n        self.next = None\r\n \r\nclass Stack:\r\n \r\n    def __init__(self):\r\n        self.head = None\r\n \r\n    def isempty(self):\r\n        if self.head == None:\r\n            return True\r\n        else:\r\n            return False\r\n \r\n    def push(self,data):\r\n \r\n        if self.head == None:\r\n            self.head=Node(data)\r\n \r\n        else:\r\n            newnode = Node(data)\r\n            newnode.next = self.head\r\n            self.head = newnode\r\n \r\n    def pop(self):\r\n \r\n        if self.isempty():\r\n            return None\r\n \r\n        else:\r\n            poppednode = self.head\r\n            self.head = self.head.next\r\n            poppednode.next = None\r\n            return poppednode.data\r\n \r\n    def peek(self):\r\n \r\n        if self.isempty():\r\n            return None\r\n \r\n        else:\r\n            return self.head.data\r\n \r\n    def display(self):\r\n \r\n        iternode = self.head\r\n        if self.isempty():\r\n            print(\"Stack Underflow\")\r\n \r\n        else:\r\n \r\n            while(iternode != None):\r\n \r\n                print(iternode.data,\"-&gt;\",end = \" \")\r\n                iternode = iternode.next\r\n            return\r\n \r\nMyStack = Stack()\r\nMyStack.push(4)\r\nMyStack.push(3)\r\nMyStack.push(2)\r\nMyStack.push(1)\r\nMyStack.display()\r\nprint(\"&#92;nTop element is \",MyStack.peek())\r\nMyStack.pop()\r\nMyStack.pop()\r\nprint(\"Stack after poping 2 times\")\r\nMyStack.display()\r\nprint(\"&#92;nTop element is \", MyStack.peek())<\/pre>\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_12639 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_12639 a\"),jQuery(\"#tab-content_12639\"));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<p><strong>Output for Stack Implementation using Linked List<\/strong><\/p>\n<pre><code>1->2->3->4->\nTop element is 1\nStack after popping 2 times\n3->4->\nTop element is 3<\/code><\/pre>\n<h3>Time and Space Complexity of Stack Implementation using Linked List<\/h3>\n<p>The time complexity for various methods is written below:<\/p>\n<ul>\n<li>push():  O(1)<\/li>\n<li>pop(): O(1)<\/li>\n<li>peek(): O(1)<\/li>\n<li>isEmpty(): O(1)<\/li>\n<li>display(): O(n)<\/li>\n<\/ul>\n<p>Space Complexity for implementation of stack using linked list is O(n) for every operation.<\/p>\n<h2>Advantages of Stack Implementation using Linked List<\/h2>\n<p>We can implement Stack using an array as well as using the Linked List, but implementation of stack using Linked List have more advantages. The advantages of implementing a stack using linked list are as follows:<\/p>\n<ul>\n<li><strong>Dynamic size:<\/strong> The size of the stack can be adjusted dynamically as the linked list can grow or shrink according to the elements pushed or popped.<\/li>\n<li><strong>Efficient memory utilization:<\/strong> The linked list uses only as much memory as required by the elements in the stack, whereas an array-based implementation might have to allocate extra memory to accommodate growth.<\/li>\n<li><strong>Flexibility:<\/strong> Linked list implementation provides more flexibility than an array-based implementation as elements can be added or removed anywhere in the list.<\/li>\n<li><strong>Ease of implementation:<\/strong> Implementing a stack using linked list is easier as it only requires a few basic operations to be performed on the linked list such as adding and removing elements from the beginning.<\/li>\n<li><strong>Improved performance:<\/strong> The linked list implementation can provide improved performance compared to an array-based implementation, especially when dealing with large stacks, as inserting or removing elements from the beginning of the linked list is an O(1) operation.<\/li>\n<\/ul>\n<h2>Disadvantages of Stack Implementation using Linked List<\/h2>\n<p>The disadvantages of implementing stack using linked list are:<\/p>\n<ul>\n<li><strong>Increased memory usage:<\/strong> As each element in the stack is stored as a separate node, linked list implementation of stack takes up more memory than other implementations such as arrays.<\/li>\n<li><strong>Slower performance:<\/strong> Operations on the linked list take more time compared to arrays, as accessing elements in linked lists require traversing through multiple nodes.<\/li>\n<li><strong>Complexity:<\/strong> Linked list implementation of the stack requires more complex coding compared to other implementations such as arrays, leading to longer development time and more bugs.<\/li>\n<li><strong>Dynamic allocation limitations:<\/strong> Dynamic allocation of memory for linked lists may be limited by the amount of available memory on the system.<\/li>\n<li><strong>Pointer management:<\/strong> Managing pointers in linked lists is more challenging compared to arrays, leading to increased risk of bugs and data corruption.<\/li>\n<\/ul>\n<h2>Applications of Stack in Data Structure<\/h2>\n<p>Stack is a commonly used data structure in computer science and has numerous applications, some of which are:<\/p>\n<ul>\n<li><strong>Expression evaluation and parsing:<\/strong> Stack is used to evaluate expressions such as infix, postfix, and prefix expressions.<\/li>\n<li><strong>Undo\/Redo operations:<\/strong> Stack can be used to maintain a history of performed actions, allowing users to undo\/redo actions as needed.<\/li>\n<li><strong>Memory management:<\/strong> Stack is used in the implementation of function calls and returns, as well as in the allocation of memory in a system.<\/li>\n<li><strong>Balancing of symbols:<\/strong> Stack can be used to check the balance of symbols in expressions and code.<\/li>\n<li><strong>Backtracking:<\/strong> Stack is often used in the implementation of algorithms that involve searching and backtracking, such as depth-first search.<\/li>\n<li><strong>Browser history:<\/strong> Stack is used to maintain a history of visited pages in a web browser, allowing users to go back and forth between pages.<\/li>\n<\/ul>\n<p><strong>Summary<\/strong><br \/>\nSo, in this article, we learned that one data structure can be used to implement another data structure. We have seen how the implementation of stack using linked list works. We have learned about various methods of Stack along with several advantages and disadvantages of Stack implementation using Linked List. We have also discussed several applications of Stack in Data Structure.<\/p>\n<h2>FAQs Related to Stack Data Structure<\/h2>\n<p><strong>1. When we implement stack using linked list?<\/strong><br \/>\nWe can implement a stack using a linked list when we need a data structure with last-in, first-out (LIFO) behavior, and the size of the stack may vary dynamically during runtime. The linked list implementation allows for efficient and dynamic adjustments to the size of the stack, making it a good choice for implementing a stack data structure.<\/p>\n<p><strong>2. What is peek() in Linked list?<\/strong><br \/>\nThe peek() method retrieves the first head of the list, but it does not remove the head.<\/p>\n<p><strong>3. What is pollLast() in the linked list?<\/strong><br \/>\nThis method removes or retrieves the last element of the list, and returns null if the list is empty.<\/p>\n<p><strong>4. What is Time Complexity for push() and pop() function of stack?<\/strong><br \/>\nThe time complexity for both operations is O(1), which means they can take a constant time to execute.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will learn about what is stack and about various operations performed on Stack in Data Structure, stack implementation using linked list with the dry run of code. We will also enlist various advantages and disadvantages of implementation of Stack using Linked List. In the last, we will discuss some of the [&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":[127],"tags":[],"class_list":["post-12629","post","type-post","status-publish","format-standard","hentry","category-stacks"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Stack Implementation using Linked List<\/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:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stack Implementation using Linked List\" \/>\n<meta property=\"og:description\" content=\"In this article, we will learn about what is stack and about various operations performed on Stack in Data Structure, stack implementation using linked list with the dry run of code. We will also enlist various advantages and disadvantages of implementation of Stack using Linked List. In the last, we will discuss some of the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-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=\"2023-02-09T11:05:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-02T06:30:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg\" \/>\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=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Stack Implementation using Linked List\",\"datePublished\":\"2023-02-09T11:05:08+00:00\",\"dateModified\":\"2023-03-02T06:30:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/\"},\"wordCount\":1918,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg\",\"articleSection\":[\"Stacks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/\",\"name\":\"Stack Implementation using Linked List\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg\",\"datePublished\":\"2023-02-09T11:05:08+00:00\",\"dateModified\":\"2023-03-02T06:30:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Stacks\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/stacks\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Stack Implementation using 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":"Stack Implementation using 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\/stack-implementation-using-linked-list\/","og_locale":"en_US","og_type":"article","og_title":"Stack Implementation using Linked List","og_description":"In this article, we will learn about what is stack and about various operations performed on Stack in Data Structure, stack implementation using linked list with the dry run of code. We will also enlist various advantages and disadvantages of implementation of Stack using Linked List. In the last, we will discuss some of the [&hellip;]","og_url":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2023-02-09T11:05:08+00:00","article_modified_time":"2023-03-02T06:30:42+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Stack Implementation using Linked List","datePublished":"2023-02-09T11:05:08+00:00","dateModified":"2023-03-02T06:30:42+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/"},"wordCount":1918,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg","articleSection":["Stacks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/","url":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/","name":"Stack Implementation using Linked List","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg","datePublished":"2023-02-09T11:05:08+00:00","dateModified":"2023-03-02T06:30:42+00:00","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1675940229755-Stack%20Implementation%20using%20Linked%20List.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/stack-implementation-using-linked-list\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Stacks","item":"https:\/\/prepbytes.com\/blog\/category\/stacks\/"},{"@type":"ListItem","position":3,"name":"Stack Implementation using 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\/12629","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=12629"}],"version-history":[{"count":4,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/12629\/revisions"}],"predecessor-version":[{"id":12836,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/12629\/revisions\/12836"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=12629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=12629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=12629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}