Skip to content

varnikarathee/Stack-Implementation-using-Linked-list

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

LINKED LIST IMPLEMENTATION OF STACK

ABOUT STACKS:

Stacks is a kind of data-structure that hold elements in a linear fashion. The principle followed is LIFO which stands Last-In-First-Out. The latter means that , the element inserted at last in stack would be removed first from same. Further the famous pointer “top” is used to highlight the top most element of the stack or last inserted element in stack.

A pictorial way of representing stack:

image

image credit

ABOUT LINKED LIST:

Linked list is a type of data-structure that holds elements through non contagious memory locations. The memory units are called as nodes that hold the data along with the address of the next unit. This way, we can save chunks of memory and increase the efficiency of the component. The address here acts as a link which helps user to traverse data , from one node to other.

The pictorial representation is below:

image

[imagecredit]https://codeforwin.org/wp-content/uploads/2015/09/Linked-list-nodes.png

IMPLEMENTATION :

The biggest advantage of implementing stack using linked list is , that it allows one to change the size of stack in runtime. The implementation begins by considering a linked list attached within a stack. The top pointer will be the lead to create a stack as it will move along the new inserted nodes.

The pictorial representation is below:

image

OPERATIONS PERFORMED:

  • PUSH: To insert element into stack using top pointer.
  • POP: To remove element from stack using top pointer.
  • PEEK: Returns the element pointed by top pointer.
  • DISPLAY: To display the element pointed by stack.
  • SPLIT: Split the stack of length n in two stacks, each of length p and q such that p+q=n.
  • COMBINE: Combine((p(i1,i2,i3...ip),q(j1,j2,...jq)) into one stack of length p+q=n. The new stack should contain the elements of the stacks p and q in any combination.

OUTPUT FOR THE CODE:

Tested in online compiler:

FILLING THE STACK:

image

SPLITTING THE STACK:

image

COMBINING THE STACK:

image

REFERENCES:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages