Saturday 10 May 2014

Stack

Stack class represents a data structure which works in Last in First Out Order. Stack class extends Vector class. In addition to operations provided by Vector, Stack class supports operations like push, pop, peek etc., Stack class provides empty constructor used to create a Stack.

import java.util.*;

class StackEmpty{
 public static void main(String args[]){
  Stack<Integer> myStack = new Stack<> ();
  
  System.out.print("Is myStack empty ");
  System.out.println(myStack.empty());
  
  /* Add Elements to myStack */
  System.out.println("\nAdding Elements to myStack");
  myStack.add(10);
  
  System.out.print("\nIs myStack empty ");
  System.out.println(myStack.empty());
 }
}

Output
Is myStack empty true

Adding Elements to myStack

Is myStack empty false



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment