Saturday 17 September 2011

EX 4 ALGO


4. Design a Java interface for ADT Stack. Develop two different classes that implement this interface, one using array and the other using linked-list. Provide necessary exception handling in both the implementations.

ALGORITHM
STEP 1: Create an interface which consists of three methods namely PUSH, POP and
    DISPLAY
STEP 2: Create a class which implements the above interface to implement the concept
              of stack through Array
STEP 3: Define all the methods of the interface to push any element, to pop the top
               element and to display the elements present in the stack.
STEP 4: Create another class which implements the same interface to implement the
                concept of stack through linked list.
STEP 5: Repeat STEP 4 for the above said class also.
STEP 6: In the main class, get the choice from the user to choose whether array
                implementation or linked list implementation of the stack.
STEP 7: Call the methods appropriately according to the choices made by the user in the
                previous step.
STEP 8: Repeat step 6 and step 7 until the user stops his/her execution

0 comments:

Post a Comment