DEV Community

Cover image for Building a Stack Implementation in Java: Mastering Data Structure Fundamentals.
Sarthak sachdeva
Sarthak sachdeva

Posted on

Building a Stack Implementation in Java: Mastering Data Structure Fundamentals.

*Hey in this code i will make a stack implementation programme *

We have a class "Stack" :
in this class i make a all method for implement stack ,
i using Integer Array to store Stack Data, and in this class we have a some other propertys ,
like : i am define the Stacksize but when i create a object to am define my new stack size , and we have a **indexvalue **of array for where to stack fill data in array and find data and remove

* THIS IS STACK CLASS

Image description

in this class we have a some method like

  1. public void size() -> to store the size of stack;
  2. public void push() -> to push data in stack
  3. public void pop() -> to remove last element of stack array
  4. public void remove() -> to remove stack element but give the indexvalue of element which one you want to remove
  5. public void getStack() -> and get all stack values

Methods implement

Image description

Image description

Image description

Image description

Image description

Image description

NOW MAKE A OBJECT AND MAKE A STACK

Image description

when an create a object to use stack to am define here my stack size 2 so am set only 2 integer data in stack

if you want to code of this stack implementation go to my github repo
github

Top comments (0)