
In a stack, we can only access the topmost element of the stack. Push, pop and peek are the main operations performed on a stack while insert, delete and traversing are the main operations performed on a linked list. Thus, this is the main difference between stack and linked list. The order of the nodes is not given by their location in memory. Where as, a linked list is a linear collection of data elements knows as nodes where each node consists value of that node and a reference pointer which points to the next node. There are basically with two principal operations in stack, which are known as push and pop. Differences between stack and Linked List.Ī stack is an abstract data type which is basically a collection of elements like a pile of books. Circular Linked List: It is similar to the above Linked List but the only difference is that the last node in the circular Linked List points to the first node, thus forming a circular chain like structure. Similar to Singly Linked List we can Insert, Delete and Traverse through a Doubly Linked List.ģ. These two reference allows forward as well as backward traversal in the Linked List.

Doubly Linked List: In doubly Linked List, each node store the data of that node and reference to the next node as well as the previous node. We can Insert, Delete and traverse through a singly Linked List.Ģ. Singly Linked List: In singly Linked List each node stores the data and the reference to the next node. This achieves optimized utilization of space.ġ. The node can reside any where in the memory and linked together to make a list. The list is not required to be contiguously present in the memory. The last node of the linked list points to null. We define two pointers head and tail which points to the first node and last node respectively.

Reference pointer which stores the address of the next node.Data field which store the data of that particular node.These nodes are stored randomly in the memory. Linked List is a linear data structure which store collection of objects known as nodes. IsEmpty() : Returns true if stack is empty i.e, if there is no elements present in the stack. Size() : It returns the current size of the size.

Peek() : It returns the element present at the top. Pop() : It removes the element from the top and returns it value. Push(x) : It is used to insert an element to the top of the stack. In stack, we can only insert elements of same data type. In case of an array, we can access any element of an array at any time, whereas in a stack, we can only access the elements of the stack in the sequential manner. So, stack is basically a container which is closed from one end. It is based on LIFO (last-in-first-out) principle in which both insertion and deletion takes place from one end only. Similarities between stack and Linked List.Ī stack is a linear data structure in which both insertion and deletion operation occurs at one end.Differences between stack and Linked List.In this article, we will be discussing about "Stack vs Linked List" in detail.
