Boostr



0 votes
20 views
Stack is a simple abstract data type or data structure . It is based on LIFO property means Last in first out .
It uses two operations on elements in the stack . Push for adding  the elements in to the stack . Pop for removing the elements from the stack . As you understand the lst element added was the first one to show the door or exit while popping from the stack .

The most important thing is to consider stack as the linear data structure as the operations push or pop are implemented at one end  of the structure  known as the top of the stack .

There are two states a stack can be in :

Overflow State :  If all the elements of the stack are filled and then we try to push  another element in to the
                             top of the stack , then the stack is said to be in the overflow state .

Underflow State : If there is no element in the stack , that is the stack is empty and we try to pop element
                               from it , then the stack is in underflow state .

Often stack is termed as restricted data structure as the small number of operations can be performed on it .

The real world example of the stack is the CD case . How you retrieve cd from the cd case . If you think carefully then you can understand the stack functionality.  In java programs , the local variables and local methods all are stored in stacks .

For example as we know that all the java applications start from the main method . Suppose then after any subsequent call to  the other methods from the main function  has been done . First we call A method , then in A we call B , in B we call C .  So first B waits for the completion of C method , when C completes then remaining of B method starts executing , and then A and in last the main method completes .

Stack  was first proposed by Alan M Turing in 1946.

So in pictorial representation it looks like this :

                   -----------------------------
                  |                C()                     |
                   -----------------------------
                  |                 B()                    |
                   -----------------------------
                  |                 A()                    |
                   -----------------------------
                  |                main()                 |
                   -----------------------------

Here in the below example :
The size is set for the stack by using setSize. Then put the values or elements you want to add to the stack.
If you want to pop elements from the stack then click on the pop button .

Pseudo Code :

1.  Set the maximum size of the stack
2.  Select an operation : push or pop
       if push
              add element to the stack that is at top
       if pop
              remove element from the stack

The famous application of the stack is the tower of honoi problem and besides that it found its usage in the expression evaluation and syntax parsing , rearranging rail road cars , backtracking ,quick sort , the stack span problem and runtime memory management .
asked Aug 24 in Java Interview Questions by Amrendra | 20 views



Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Related Questions



Welcome to Knowledge Boostr, where you can ask questions and receive answers from other members of the community.
This is a collaboratively edited question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

http://boostr.in Q&A for professional and enthusiast programmers http://boostr.in Q&A for professional and enthusiast programmers http://boostr.in Q&A for professional and enthusiast programmers http://boostr.in Q&A for professional and enthusiast programmers


23,471 questions
40,135 answers
12 comments
23,609 users