728x90 AdSpace

Trending

Stack data structure


A Stack is a container of objects that are inserted and removed according to the LIFO principle.
There are wide range of application using stacks.
Stacks are used for procedure calls and recursion.
stacks are an important application to the run time environments of the modern procedural languages, such as c, c++ and Java.Each thread in a running program written in one of these languages has a private stack, called the method stack, which is used to keep track of local variables and other important information on methods, as they invoked during execution.

Another application of stack:-
Internet web browsers store the address of recently visited sites on a stack.Each time a user visits a new site, that site's address is pushed onto the stack of address.The browser then allows the user to pop back to previously visited sites using the back button.
Stack Abstract Data Type(ADT)
  • push(O) : inserting the object.
  • pop(O) : removing the object from stack.
  • peek() : returns top Object
  • size() : returns size of stack.
  • isEmpty() :return true if stack is empty.
  • peek() : returns top Object


Java Stack API
  • public java.util.Stack();//constructor
  • public E push(E);
  • public synchronized E pop();
  • public synchronized E peek();
  • public boolean empty();
  • public synchronized int search(java.lang.Object);





            

    Recursion application:-

    One of the benefits of using stack to implement method invocation is that it allow programs to use recursion.
    Recursion is nothing but defining something in terms of itself.
    We must allows design a recursion method so that it is guaranteed to terminate at some point.If terminate condition is not provided it will not run forever.It will instead at some point , use up all the memory available for the method stack and generate an OutOfMemory error.Recursion can be very powerful, as it often allows us to design simple and efficient programs for difficult problems.
    Design a application in java which simulates the browser application in stacks.

    Clich Here to download dot class and jar files.
    Contact Us for Source copy.
    Stack data structure Reviewed by Unknown on 10:26 Rating: 5 A Stack is a container of objects that are inserted and removed according to the LIFO principle. There are wide range of application ...

    No comments: