Array implementation of Stack Data structure in Java

A stack is a simple data structure for storing data. In stack, the order in which the data arrives is important. A pile of books is a good example of stack.
A stack is an ordered list in which insertion and deletion are done at one end, where end is called top. The last element inserted is the first one to be deleted. Hence, it is called Last in First Out (LIFO) or First in Last Out (FILO) list

In computer science, a stack is a particular kind of abstract data type or collection in which the principal (or only) operations on the collection are the addition of an entity to the collection, known as push and removal of an entity, known as pop. Often a peek or top operation is also implemented, returning the value ofthe top element without removing it.

Stack Operations
Main operations

  • void push(int data) : Insert data onto stack.
  • int pop() : Removes and returned last inserted element from the stack
Auxiliary operations
  • int top() or peek() : Returns the last inserted elements without removing it.
  • int size() :  Returns the number of elements stored in stack.
  • boolean isStackFull() : Check whether stack is full or not.
  • boolean isEmpty() : Check whether stack is empty or not.

Click here to read more


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s